BookmarkSubscribeRSS Feed
Wouter
Obsidian | Level 7
Hi,

I've created a code in order to create a report, in which I make use of several dates (month ends) which has to be entered at the top of the code (variables with the %let statement). But... to make life easier, I thought it would be a great idea to just enter 1 date, and let SAS compute the other dates.

Right now, I've got to enter 4 dates as shown below:

%let period1 = '1aug2010:0:0'dt; * the reporting month we're looking at;
%let period2 = '1jul2010:0:0'dt; * the month before the reporting month we're looking at;
%let period3 = '1jun2010:0:0'dt; * 2 months before reporting month;
%let period4 = '1sep2010:0:0'dt; *the month after the reporting month we're looking at;

So I tried to create the other dates with the following statement, based on the date given at period1 (in this example, I tried to create period2), with different statements:

%let period2 = intnx('month',&period1., -1);
%let period2 = intnx('month',&period1, -1);
%let period2 = intnx('month','&period1'dt, -1);

But... none of these statements are working...

After searching a lot, I can't figure out what I'm doing wrong. Can anyone help me with this?

Thanks in advance!!
1 REPLY 1
Cynthia_sas
SAS Super FREQ
Hi:
%LET is merely assigning TEXT strings to &PERIOD2, as shown in the SAS log below:
[pre]
111 %let period1 = '1aug2010:0:0'dt; * the reporting month we're
111! looking at;
112 %let period2 = '1jul2010:0:0'dt; * the month before the
112! reporting month we're looking at;
113 %let period3 = '1jun2010:0:0'dt; * 2 months before reporting
113! month;
114 %let period4 = '1sep2010:0:0'dt; *the month after the reporting
114! month we're looking at;
115
116 %put *** before INTNX:;
*** before INTNX:
117 %put period1 = &period1;
period1 = '1aug2010:0:0'dt
118 %put period2 = &period2;
period2 = '1jul2010:0:0'dt
119 %put period3 = &period3;
period3 = '1jun2010:0:0'dt
120 %put period4 = &period4;
period4 = '1sep2010:0:0'dt
121 %put *** *** *** *** ***;
*** *** *** *** ***
122
123
124 %let period2 = intnx('month',&period1., -1);
125 %put *** after INTNX 1:;
*** after INTNX 1:
126 %put period2 = &period2;
period2 = intnx('month','1aug2010:0:0'dt, -1)
127
128 %let period2 = intnx('month',&period1, -1);
129 %put *** after INTNX 2:;
*** after INTNX 2:
130 %put period2 = &period2;
period2 = intnx('month','1aug2010:0:0'dt, -1)
131
132 %let period2 = intnx('month','&period1'dt, -1);
133 %put *** after INTNX 3:;
*** after INTNX 3:
134 %put period2 = &period2;
period2 = intnx('month','&period1'dt, -1)
[/pre]

So if you want the INTNX function to actually be INVOKED and -do- something, you would need to use the %SYSFUNC macro function in order to assign a different value to a new macro variable. For example, a simpler date-related function shows how to extract the month, day and year from a macro variable value that represents a date. Note the "&bday"d construct in the date function usage -- I don't favor "pre-quoting" macro variable values when the values are assigned:
[pre]
135 %let bday = 15nov1950;
136
137 %let mm = %sysfunc(month("&bday"d));
138 %let bd = %sysfunc(day("&bday"d));
139 %let yr = %sysfunc(year("&bday"d));
140
141 %put month of bday = &mm;
month of bday = 11
142 %put day of bday = &bd;
day of bday = 15
143 %put year of bday = &yr;
year of bday = 1950
[/pre]

cynthia

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 755 views
  • 0 likes
  • 2 in conversation