Hi,
I am having the columns as AS_OF_DT and dw_Load_time as date columns and the format is numeric.
I need to take the latest of these date values.
AS_OF_DT DW_LOad_time
19601 19614.462789
19589 19614.462789
19235 19603.345679
19590 19405.213453
19560 19349.298756
19340 18777.132456
19430 18796.654378
I need to refer these in the codes as macro variables.
Could any one help me on how to go on this.
Regards,
Sid
proc sql noprint;
select max(AS_OF_DT), max(DW_LOad_time) into :max_date, :max_time from have;
quit;
%put &max_date &max_time;
I was unable to get the values in correct format i.e., DW_Load_time should come as datetime format.
Regards,
Sid
First you need to convert dates into datetimes multiplying by 86400:
data have;
input AS_OF_DT DW_LOad_time;
format AS_OF_DT DW_LOad_time datetime.;
as_of_dt=as_of_dt*86400;
dw_load_time=dw_load_time*86400;
cards;
19601 19614.462789
19589 19614.462789
19235 19603.345679
19590 19405.213453
19560 19349.298756
19340 18777.132456
19430 18796.654378
;
run;
proc sql noprint;
select max(AS_OF_DT) as max_DT format datetime., max(DW_LOad_time) as Max_DW_Load_time format datetime. into :max_date, :max_time from have;
quit;
%put &max_date &max_time;
CTorres
As suggested by CTorres, to get DW_Load_time as datetime format first convert DW_Load_time into seconds then apply datetime format.
Assuming your load time is actually a date and your data provided is incorrect:
proc sql noprint;
select max(put(AS_OF_DT, date9.)), max(put(DW_LOad_time, datetime21.)) into :max_date, :max_time from have;
quit;
%put &max_date &max_time;
Assuming your load time is actually a date and you need to convert it to datetime
proc sql noprint;
select max(put(AS_OF_DT, date9.)), max(put(dhms(DW_LOad_time,0,0,0), datetime21.)) into :max_date, :max_time from have;
quit;
%put &max_date &max_time;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.