BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
data dat;

file_date=substr(put("&sysdate"d,mmddyy10.),7,4)||'-'||substr(put("&sysdate"d,mmddyy10.),1,2);
run;

File_date resolves to 2009-06.

How to get 2009-05 instead?
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
I suggest working with the SAS DATE numeric-type variables for a more straightforward technique, and also so you can use INTNX, for deriving date values and date-strings.

In a DATA step, use the PUT function with a SAS DATE type variable, if you need to assign a character-type variable, for some purpose:

data _null_;
mytoday = "&sysdate9"d;
format mytoday date9. ;
today_yymmdd = put( mytoday,yymmdd6.);
putlog _all_;
run;

The SAS support http://support.sas.com/ website provides SAS-hosted documentation and supplemental technica/conference papers on this topic - use the website SEARCH or a Google advanced search, adding the site:sas.com parmeter to limit your search to the SAS.COM site.

Scott Barry
SBBWorks, Inc.

SAS DOC - Working with Dates in the SAS System:
http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001304321.htm


Using SAS® Dates and Times – A Tutorial
Jonas V. Bilenas, JP Morgan Chase, Wilmington, DE
http://www2.sas.com/proceedings/forum2007/226-2007.pdf


TS-668
SAS Dates, Times, and Interval Functions
Definitions and Explanations
SAS Dates, Times, and Datetimes:
http://support.sas.com/techsup/technote/ts668.pdf
deleted_user
Not applicable
Hello SASPhile,

This could be the solution to your problem:

data dat;
length file_date $7;
file_date=put(intnx('month',date(),-1),YYMMD7.);
put file_Date=;
run;

Could you tell whether this solves the problem?

Regards,

Yoba
Peter_C
Rhodochrosite | Level 12
and the equivalent code to operate on macro variables, is:
%let last_month = %sysfunc( intnx( month, "&sysdate9"d, -1 ), yymmd7 );
%put &last_month ;

(works for me)

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 4047 views
  • 0 likes
  • 4 in conversation