Hi Team,
I have a date as input and I need to get last 6 dates in a continues manner for the same gap between dates.
for eg I have a date %let yearmt = 202201 so I need dates as 202110 ,202107,202104,202101,202010,202007 . How can I calculate it using a macro?
Regards
Kajal
Use built-in SAS functions to compute months (and all calendar arithmetic)
%let yearmt=202201;
%let yearmtn=%sysfunc(inputn(&yearmt,yymmn6.));
%macro dothis;
%do i=1 %to 6;
%let thismonth=%sysfunc(intnx(month,&yearmtn,%eval(&i*-3),b));
%put %sysfunc(putn(&thismonth,yymmn6.));
%end;
%mend;
%dothis
Use built-in SAS functions to compute months (and all calendar arithmetic)
%let yearmt=202201;
%let yearmtn=%sysfunc(inputn(&yearmt,yymmn6.));
%macro dothis;
%do i=1 %to 6;
%let thismonth=%sysfunc(intnx(month,&yearmtn,%eval(&i*-3),b));
%put %sysfunc(putn(&thismonth,yymmn6.));
%end;
%mend;
%dothis
thank you @PaigeMiller
Why does the subject line for your post say "4 calendar dates" and the body of the question "last 6 dates"?
Given any "date" what is the rule for determining what the dates would be? I can guess but really would prefer not to rely on guesses when programming.
Do all of the values go into one macro variable? 4 macro variables? 6 macro variables? Data step variable(s)? In other words, what is the result to look like.
Note: Macro variables are text. So 202201 is not a "date" but 6 characters.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: