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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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