BookmarkSubscribeRSS Feed
Siddhartha
Calcite | Level 5

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

5 REPLIES 5
stat_sas
Ammonite | Level 13

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;

Siddhartha
Calcite | Level 5

I was unable to get the values  in correct format i.e., DW_Load_time should come as datetime format.

Regards,

Sid

CTorres
Quartz | Level 8


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

stat_sas
Ammonite | Level 13

As suggested by , to get DW_Load_time as datetime format  first convert DW_Load_time into seconds then apply datetime format.

Reeza
Super User

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 6286 views
  • 0 likes
  • 4 in conversation