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

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.Months.PNG

 

 

Regards,

Ashish

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16
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;
Thanks,
Jag

View solution in original post

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16
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;
Thanks,
Jag
ASHISH2525
Quartz | Level 8

Thank you Jag ! I was looking for the same.

 

Regards,

Ashish

novinosrin
Tourmaline | Level 20

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. 

ccaulkins9
Pyrite | Level 9

if _n_=1 then continuous_month=month;
else continuous_month+1

 

Help! I'm being overtaken by hackers, copycat hacker no less -

e-SAS regards,

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Tips for filtering data sources in SAS Visual Analytics

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.

Discussion stats
  • 4 replies
  • 662 views
  • 6 likes
  • 4 in conversation