BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5
HI i am having differnt months and year if the reporting month is mar10 then i should create new variable called mar_diff and it should minus from the last two months jan10-feb10 and if reporting month is jan10 it should minus from nov-09-dec-09 and i should create new variable jan10_diff like that

data temp;
input oct09 nov09 dec09 jan10 feb10 mar10;
cards;
10 11 12 13 14 15 16
run;
1 REPLY 1
Ksharp
Super User
Hi.
Your data structure is not look good. So I change it .



[pre]
data temp;
input oct09 nov09 dec09 jan10 feb10 mar10;
cards;
10 12 12 13 14 15 16
20 21 22 22 24 24 26
;
run;
data op(keep=_count count val var);
set temp;
count+1;
array month{*} _numeric_;
do i=1 to dim(month);
var=vname(month{i});
val=month{i};
_count+1;
output;
end;
call missing (_count);
run;
data opp;
set op;
output;
var=cats(var,'_diff');
val=lag2(val)-lag(val);
if _count in (1 2) then call missing(val);
output;

run;
proc transpose data=opp out=want(drop=_name_ count:);
by count;
id var;
var val;
run;


[/pre]



Ksharp

Message was edited by: Ksharp

Message was edited by: Ksharp Message was edited by: Ksharp

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 525 views
  • 0 likes
  • 2 in conversation