Hi All,
I have a date in the form of year month and I want the last month date from the code . for eg I have 202210 and I want the code to provide me 202209.
tried code below but didn't work.
%let yearmonth = 202210; data one; call symputx('P_Month', month(intnx('month',&yearmonth,-1))); run; %put &P_Month;
%let yearmonth = 202210;
data _null_;
dt = input(put(&yearmonth., 6.), yymmn6.);
call symputx('P_Month', put(intnx('month', dt, -1, 'b'), yymmn6.));
run;
%put &P_Month.;
%let yearmonth = 202210;
data _null_;
dt = input(put(&yearmonth., 6.), yymmn6.);
call symputx('P_Month', put(intnx('month', dt, -1, 'b'), yymmn6.));
run;
%put &P_Month.;
SAS dates are counts of days, with 1960-01-01 being day zero.
So your INTNX function starts with a date that is 202,210 days after 1960-01-01, so quite far in the future.
As already indicated, you must convert your year/month string to a SAS date first by using the INPUT function with a proper informat.
%let yearmonth = 202210; %let last_month=%sysfunc(intnx(month, %sysfunc(inputn(&yearmonth.,yymmn6.)) ,-1),yymmn6.) ; %put &=last_month. ;
Thank you so much team.
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: