Hello
I want to ask a question regarding creating a sas macro parameter.
User define current month (Let's say Sep 2020) with YYMM format.
There are 2 tasks:
1-Create macro parameter of start of previews month(number that represent sas date).
2-Create macro parameter of previews month in YYMM structure (Result:1908)
I have a problem to perform the 2nd task
thank you
Mer
@Ronein wrote:
Thank you.
The desired outcome is 1908 ( by YYMM structrure).
In the code that you sent I get sas date value and not 1908
Dead simple:
%let begin_last_month=%sysfunc(intnx(month,%sysfunc(inputn(20&in.01,yymmdd8.)),-1,b),yymmn4.);
%put &begin_last_month.;
%let Cur_Mon_YYMM=1909;/*YYMM structure*/
%let Cur_Mon_date=%sysfunc(inputn(&Cur_Mon_YYMM.,yymmn4.));
/*SAS date:number of days since 1.1.1960*/
%put &Cur_Mon_date;
%let Prev_mon=%sysfunc(intnx(month,&Cur_Mon_date.,-1));
/*SAS date:number of days since 1.1.1960*/
%put &Prev_mon;
%let Prev_mon_YYMM=?????
For the 2nd:
%let in=2009;
%let begin_last_month=%sysfunc(intnx(month,%sysfunc(inputn(20&in.01,yymmdd8.)),-1,b));
data _null_;
x=&begin_last_month;
put x yymmdd10.;
run;
Thank you.
The desired outcome is 1908 ( by YYMM structrure).
In the code that you sent I get sas date value and not 1908
Then you can assign it the proper format.
@Ronein wrote:
Thank you.
The desired outcome is 1908 ( by YYMM structrure).
In the code that you sent I get sas date value and not 1908
Dead simple:
%let begin_last_month=%sysfunc(intnx(month,%sysfunc(inputn(20&in.01,yymmdd8.)),-1,b),yymmn4.);
%put &begin_last_month.;
PS your subject line asked specifically for a SAS date value.
Thank you All,
I wrote a summary based on the posts.
%let Cur_YYMM=1909;
%let lastMon_YYMM=%sysfunc(intnx(month,%sysfunc(inputn(&Cur_YYMM,yymmn4.)),-1),yymmn4.);
%put &lastMon_YYMM.;
/*1908*/
%let StartOflastMon_date=%sysfunc(intnx(month,%sysfunc(inputn(&Cur_YYMM,yymmn4.)),-1,b));
%put &StartOflastMon_date.;
/*21762 that represent #days from 1.1.1960 til 01Aug2020*/
%let EndOflastMon_date=%sysfunc(intnx(month,%sysfunc(inputn(&Cur_YYMM,yymmn4.)),-1,E));
%put &EndOflastMon_date.;
/*21792 that represent #days from 1.1.1960 til 31Aug2020*/
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.