The following file I created works to create the dataset I want for each file individually. I would have loaded each file and the two separate datasets would come out like this:
Medication 1 Dataset
Patientid Adhash{patientid}
1223 .95
1224 .56
1225 .78
1226 .99
1227 .67
Medication 2 Dataset
Patientid Adhash{patientid}
1226 .85
1227 .66
1487 .45
1489 .99
1500 .32
Now I want to use my same code to combine two files by Patientid key again WHILE CREATING DISTINCT HASHES(VARIABLES) FOR EACH FILE'S ADHASH{PATIENTID} so that the output will look like:
Patientid ADHash{patientid}Med1 ADHash{patientid}Med2
1223 .95
1224 .56
1225 .78
1226 .99 .85
1227 .67 .66
1487 .45
1489 .99
1500 .32
Relevant portion of code for individual file:
open(FH ,"$file")||die "Couldn't open infile";
...
...
...
...etc,
my %dmhash = ();
my %dohash = ();
my %adhash = ();
for ($i=1; $i<@patientid; $i++){
$dmhash{$patientid[$i]} += $intdaymiss[$i];
$dohash{$patientid[$i]} += $daysobs[$i];}
#Creating an adherence "hash" (adhash) that is calculated from the daysmissed hash (dmhash) and daysobserved hash (dohash)
for $id (keys %dmhash){
if(($dohash{$id})==0) {
$adhash{$id}=nil;
}
else{$adhash{$id} = 1-(($dmhash{$id})/($dohash{$id}));
}
}
print OUTFILE "ID\tDays Missed\tDays Observed\tAdherance\n";
foreach my $id (sort(keys(%adhash))) {
print OUTFILE "$id\t$dmhash{$id}\t$dohash{$id}\t$adhash{$id}\n";
}
Now I've created a directory and an array for all the files' names in the directory (@files)
What advice do you have for creating a loop that loops through each file and the proper way to print the merged output I mentioned that I want.
Thanks guys!!!
Medication 1 Dataset
Patientid Adhash{patientid}
1223 .95
1224 .56
1225 .78
1226 .99
1227 .67
Medication 2 Dataset
Patientid Adhash{patientid}
1226 .85
1227 .66
1487 .45
1489 .99
1500 .32
Now I want to use my same code to combine two files by Patientid key again WHILE CREATING DISTINCT HASHES(VARIABLES) FOR EACH FILE'S ADHASH{PATIENTID} so that the output will look like:
Patientid ADHash{patientid}Med1 ADHash{patientid}Med2
1223 .95
1224 .56
1225 .78
1226 .99 .85
1227 .67 .66
1487 .45
1489 .99
1500 .32
Relevant portion of code for individual file:
open(FH ,"$file")||die "Couldn't open infile";
...
...
...
...etc,
my %dmhash = ();
my %dohash = ();
my %adhash = ();
for ($i=1; $i<@patientid; $i++){
$dmhash{$patientid[$i]} += $intdaymiss[$i];
$dohash{$patientid[$i]} += $daysobs[$i];}
#Creating an adherence "hash" (adhash) that is calculated from the daysmissed hash (dmhash) and daysobserved hash (dohash)
for $id (keys %dmhash){
if(($dohash{$id})==0) {
$adhash{$id}=nil;
}
else{$adhash{$id} = 1-(($dmhash{$id})/($dohash{$id}));
}
}
print OUTFILE "ID\tDays Missed\tDays Observed\tAdherance\n";
foreach my $id (sort(keys(%adhash))) {
print OUTFILE "$id\t$dmhash{$id}\t$dohash{$id}\t$adhash{$id}\n";
}
Now I've created a directory and an array for all the files' names in the directory (@files)
What advice do you have for creating a loop that loops through each file and the proper way to print the merged output I mentioned that I want.
Thanks guys!!!