Hi all,
I need help (SAS code) in calculating difference in minutes and hours for datetime variables. I have attached a copy of my data.
Here I have several Reg_Nos and the corresponding culture_dates (datetime). Some of the Reg_nos have multiple culture_date which are in different row compared to the first culture_date for that Reg_no (eg. I have highlighted in red).
I need to find the difference in minutes and hours from the first culture_date to the next cultre_date if a Reg_No has more than one culture_date.
Thanks for the help!
Satish
Note: you'd want to not count the cases where the current reg_no and the previous reg_no don't match, again LAG can help you determine this.
Here's a sample code using retain instead of lag.
data reg_no(drop=day row);
do reg_no=1 to 10;
do row = 1 to reg_no;
day=mdy(12,31,2014);
culture_date= DHMS(day+row,reg_no+row*row,reg_no,0) ;
format culture_date datetime.;
format day ddmmyy.;
output;
end;
end;
run;
data reg_no2(drop=lastdate);
set reg_no;
retain lastdate firstdate;
format delay time. ;
format delay_since_first time. ;
by reg_no;
if first.reg_no then
do;
lastdate=culture_date;
firstdate=culture_date;
end;
else do;
delay= culture_date - lastdate;
lastdate= culture_date;
delay_since_first= culture_date - firstdate;
end;
run;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.