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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

@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.;

View solution in original post

7 REPLIES 7
Ronein
Onyx | Level 15

%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=?????
Kurt_Bremser
Super User

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;
Ronein
Onyx | Level 15

Thank you.

The desired outcome is 1908 ( by YYMM structrure).

In the code that you sent I get sas date value and not 1908

 

PaigeMiller
Diamond | Level 26

Then you can assign it the proper format.

--
Paige Miller
Kurt_Bremser
Super User

@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.;
Ronein
Onyx | Level 15

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*/

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1878 views
  • 1 like
  • 3 in conversation