Hi All,
I have created numeric months for reporting so that using rank i will fixed desired output.
But problem is that treat as function only create 12 months for two year 2018 & 2019. means Dec-18 is 12 and Dec-19 is also 12. i wanted to have it like Dec 18 should be Jan 19 should be 13 and so on.
Let me know is there workaround for this.
Regards,
Ashish
data have;
input years$;
date=input(cats('01-',years),anydtdte.);
yr=year(input(cats('01-',years),anydtdte.));
month=month(input(cats('01-',years),anydtdte.));
lagmonth=lag(month);
cards;
Aug-18
Sep-18
Oct-18
Nov-18
Dec-18
Jan-19
Feb-19
Mar-19
Apr-19
May-19
Jun-19
Jul-19
Aug-19
Sep-19
Oct-19
Nov-19
Dec-19
;
proc sort data=have;
by yr date ;
run;
data want;
set have;
by yr date;
retain count;
if first.yr then count=lagmonth;
month2=coalesce(count+month,month);
drop month yr count lagmonth date;
run;
data have;
input years$;
date=input(cats('01-',years),anydtdte.);
yr=year(input(cats('01-',years),anydtdte.));
month=month(input(cats('01-',years),anydtdte.));
lagmonth=lag(month);
cards;
Aug-18
Sep-18
Oct-18
Nov-18
Dec-18
Jan-19
Feb-19
Mar-19
Apr-19
May-19
Jun-19
Jul-19
Aug-19
Sep-19
Oct-19
Nov-19
Dec-19
;
proc sort data=have;
by yr date ;
run;
data want;
set have;
by yr date;
retain count;
if first.yr then count=lagmonth;
month2=coalesce(count+month,month);
drop month yr count lagmonth date;
run;
Thank you Jag ! I was looking for the same.
Regards,
Ashish
Hi @ASHISH2525 Since you wrote that you have continuous data and the starting month value that you have already created.
if _n_=1 then continuous_month=month;
else continuous_month+1
is all you need.
if _n_=1 then continuous_month=month;
else continuous_month+1
Help! I'm being overtaken by hackers, copycat hacker no less -
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.
Find more tutorials on the SAS Users YouTube channel.