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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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