Help using Base SAS procedures

Reg:Dates

Reply
Regular Contributor
Posts: 229

Reg:Dates

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;
Super User
Posts: 10,020

Re: Reg:Dates

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_ countSmiley Happy;
by count;
id var;
var val;
run;


[/pre]



Ksharp

Message was edited by: Ksharp

Message was edited by: Ksharp Message was edited by: Ksharp
Ask a Question
Discussion stats
  • 1 reply
  • 102 views
  • 0 likes
  • 2 in conversation