SAS - Using the retain statement -


i have dataset ids, dates , amounts. each id may have few rows depending on transaction amounts , number of transactions performed. need use retain statement find difference in time between first change in amount. know need retain 3 variables unsure how go this? great

here's basic use of retain statement. can't tell need description. maybe need retain second variable , use if ... ... else ... (dates match, ...., else....) anyway, maybe started...

 data in;     input id var1 ;     datalines;       1  12          1  24          1  26          2  20          2  25          2  11    ;   data out (drop=var1_lag);    set in;     id;     if first.id diff=.;    else             diff = var1 - var1_lag;    var1_lag = var1;    retain var1_lag;   proc print data=out;   run;  

output:

 obs    id    var1    diff    1      1     12        .   2      1     24       12   3      1     26        2   4      2     20        .   5      2     25        5   6      2     11      -14 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -