attrib arrivaldatetime format=datetime19.;
arrivaldatetime=input(put(HOSPARRIVALDATE,date9.)||put(HOSPARRIVALTIME,time8.),datetime.);
After much online searching, I have been unable to find a way to concatenate dates and military times. Any suggested code will be much appreciated!
Better use
attrib arrivaldatetime format=datetime19.;
arrivaldatetime = dhms(HOSPARRIVALDATE, hour(HOSPARRIVALTIME), minute(HOSPARRIVALTIME), second(HOSPARRIVALTIME));
your code was missing a separator between date and time.
It may be better to use DHMS() function to build your date time variable.
Can you please post sample data, SAS shouldn't have issues with 24 hour times, which is what I'm assuming is "Military" time.
Yes, i've attached a sample file.
You can see the data i'm working from in columns labeled:
HOSPARRIVALTIME | HOSPARRIVALDATE | arrivaldatetime |
arrivaldatetime only concatenates when hosparrivaltime is < 13:00.
The bloodproduct and headct columns with missing data are due to non-concatenation of times > 13:00 (done in an earlier step with the previously mentioned sas code).
Note about Circular references in formula makes it likely there are multiple issues with the data in this format.
Could you post the data as a text file? Save the file as CSV and name with a TXT extension before posting to the forum.
Please show the entire SAS code you have used.
If you are trying to combine stuff in Excel then it is not a SAS question.
The values I see in the spreadsheet and the message about circular reference makes me believe this is not the actual in SAS.
This is all done in SAS, not excel. Here is the full sas code. Very simple, i'm importing 6 files (I hid the file name), merging 3 'unique' files and 3 'propogated' files across study years, identifying the first procedure (either head CT or blood product), merging, then trying to get time elapsed. The attached file is after the merged step.
%macro import (sheet =, year = , DATAFILE=);
PROC IMPORT OUT= HS.import_&year._&sheet
DATAFILE= &DATAFILE
DBMS=XLSX REPLACE;
SHEET = &sheet;
RUN;
%mend import;
%import (sheet = unique, year = 2013, DATAFILE = "(hidden)");
%import (sheet = unique, year = 2014, DATAFILE = "(hidden)");
%import (sheet = unique, year = 2015, DATAFILE = "(hidden)");
%import (sheet = prop, year = 2013, DATAFILE = "(hidden)");
%import (sheet = prop, year = 2014, DATAFILE = "(hidden)");
%import (sheet = prop, year = 2015, DATAFILE = "(hidden)");
Data hs.propogated;
Set import_2013_prop import_2014_prop import_2015_prop;
attrib procdatetime format=datetime19.;
procdatetime=input(put(proc_start_date,date9.)||put(proc_start_time,time8.),datetime.);
run;
proc sort data=hs.propogated;
by registry_ procedure descending procdatetime ;
run;
Data hs.coded_propogated;
Set hs.propogated;
by REGISTRY_;
KEEP REGISTRY_ first_headCT first_blood ;
RETAIN first_headCT first_blood ;
IF FIRST.REGISTRY_ THEN do; first_headCT = .; first_blood = .; END;
if procedure = 'BLOOD' and procdatetime NE . then first_blood=procdatetime;
if procedure = 'HEADCT' and procdatetime NE . then first_headct=procdatetime;
format first_headct first_blood datetime19.;
IF LAST.REGISTRY_ THEN OUTPUT;
Run;
data hs.coded_unique;
set import_2013_unique import_2014_unique import_2015_unique;
attrib arrivaldatetime format=datetime19.;
arrivaldatetime=input(put(HOSPARRIVALDATE,date9.)||put(HOSPARRIVALTIME,time8.),datetime.);
run;
proc sort data=hs.coded_propogated; by registry_; run;
proc sort data=hs.coded_unique; by registry_; run;
data hs.merged;
merge hs.coded_propogated hs.coded_unique;
by registry_;
arrival_to_ct = first_headCT - arrivaldatetime;
ct_to_blood = first_headCT - first_blood ;
format arrival_to_ct ct_to_blood hhmm.;
run;
data merged;
set hs.merged (keep = registry_ first_headCT first_blood hosparrivaltime hosparrivaldate arrivaldatetime arrival_to_ct ct_to_blood);
run;
PROC EXPORT DATA= WORK.MERGED
OUTFILE= "\\vmware-host\Shared Folders\Desktop\merged.csv"
DBMS=CSV LABEL REPLACE;
PUTNAMES=YES;
RUN;
Better use
attrib arrivaldatetime format=datetime19.;
arrivaldatetime = dhms(HOSPARRIVALDATE, hour(HOSPARRIVALTIME), minute(HOSPARRIVALTIME), second(HOSPARRIVALTIME));
your code was missing a separator between date and time.
so simple- thanks for the fix!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.