BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tparvaiz
Obsidian | Level 7

in our sas program we have dates thta are hard coded, something like this

 

%let YYYYMM = 201704;
%let date1 = '01Apr2017'd;
%let date2 = '01May2017'd;

 

everythime we run a report, have to manually change them. can yo uplease advise how to automate these values.

 

YYYMM is the previous month and year

date1 is the first date of the previous month

date2 is the first daty of the current month

 

thanks in advance

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Like this?

 

%let YYYYMM =         %sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-1)),yymmn6.));
%let date1  = %str(%')%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-1)),date9.))%str(%')d;
%let date2  = %str(%')%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()), 0)),date9.))%str(%')d;

View solution in original post

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

Like this?

 

%let YYYYMM =         %sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-1)),yymmn6.));
%let date1  = %str(%')%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-1)),date9.))%str(%')d;
%let date2  = %str(%')%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()), 0)),date9.))%str(%')d;
ballardw
Super User

Or

data _null_;
   call symputx('YYYMM',put(intnx('month',today(),-1),yymmn6.));
   call symputx('date1',intnx('month',today(),-1,'b'));
   call symputx('date2',intnx('month',today(),0,'b'));
run;

 

 

Which is much easier on my eyes than nested %sysfunc.

Yes, this does not have '01Apr2017'd but the numeric value that the date resolves to. Unless you are actually putting date1 and date2 into text output such as a title then the numeric will work just fine.

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
  • 2 replies
  • 865 views
  • 2 likes
  • 3 in conversation