BookmarkSubscribeRSS Feed
Dwight09
Calcite | Level 5

%let dsin = test;

%let rc = %sysfunc(open(&dsin, I));

%if &rc % then %do;

   %let cdate = %sysfunc(attrn(&rc, crdte));

%end;

Question is: How to get cdate in date9. format? This can be done using data null and call symput but I would like to know if can be done in above method?

6 REPLIES 6
ballardw
Super User

What result are you currently getting for CDATE? That is likely to be OS dependent so we need to see what you have.

The likely solution will involve some form of %sysfunc(inputn or inputc depending, with a date informat. That would be inside a %sysfunc(putn({long expression},date9.)0;

Dwight09
Calcite | Level 5

crdate value is 1636523977. Tried %sysfunc(putn(&crdate, date9.)) but not working. I get ********* [all asteriks]

ballardw
Super User

When I tried a DATETIME16. format with that value of 1636523977 for cdate I get 10NOV11:05:59:37. Does that look like the correct date for your example? If so you want the DATEPART of CDATE.

Peter_C
Rhodochrosite | Level 12

assuming internal value of &crdte is a sas date (#days since 1/1/1960)

%let date_constant = %sysfunc( putn( &crdte, date11 )) ;

* date11 looks even better than date9, and works just as well in:

  where date_var <= "&date_constant"d 

Reeza
Super User

You can do it with nested functions. sysfunc has a put by default so you don't need a putn either.

However your variable is actually a datetime variable not a date variable so you need to take the datepart of the datetime variable first, then do the format.

%let cdate=%sysfunc(datepart(%sysfunc(attrn(&rc, crdte))),date9.);

Peter_C
Rhodochrosite | Level 12

at some point SAS formats were extended with a few prefixed DT - these are designed for datetime values.

When extracting just the date part of "created date", we don't need the datepart() function, just DTDATE9

%let cdate= %sysfunc(attrn(&rc, crdte),DTdate9 );

sas-innovate-2024.png

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.

 

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
  • 6 replies
  • 1021 views
  • 0 likes
  • 4 in conversation