hi ,
below is the small snippet :
%let year_month=202201; data try; temp=&year_month.-1; run;
I want my temp to be 202112 not 202200 . Can you please help me in give a quick solution.
Thanks in advance !
You want it be a DATE type variable or just simple NUMERIC type variable ?
%let year_month=202201; data try; temp=intnx('month',input("&year_month.01",yymmdd10.),-1); format temp yymmn6.; run;
Do you want it in a macro variable or a Data Step variable?
You want it be a DATE type variable or just simple NUMERIC type variable ?
%let year_month=202201; data try; temp=intnx('month',input("&year_month.01",yymmdd10.),-1); format temp yymmn6.; run;
I don't know if this is the best solution, but here's what I have.
%let yearmonth = %sysfunc(intnx(month, %sysfunc(inputn(202201, yymmn6.)),-1,e));
%put &yearmonth.;
82 %put &yearmonth.; 22645
@maguiremq wrote:
I don't know if this is the best solution, but here's what I have.
%let yearmonth = %sysfunc(intnx(month, %sysfunc(inputn(202201, yymmn6.)),-1,e)); %put &yearmonth.;
82 %put &yearmonth.; 22645
Close. If you want to generate the digit string in YYYYMM style then tell %SYSFUNC() to apply the YYMMN format to the value.
1725 %let yearmonth = %sysfunc(intnx(month, %sysfunc(inputn(202201, yymmn6.)),-1,e),yymmn6.); 1726 %put &=yearmonth; YEARMONTH=202112
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.