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)

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