Hi Experts,
Now I have the annual data for one variable ("total_pps") for each company(labeled as "GVKEY"), and I'd like to calculate the difference between current year's "pps" and the pps for the last year for each company and make it as current year's difference. For example, for gvkey=001045, the difference between pps in 1993 and pps in 1992 should be the "diff_pps" for 1993 which will become a new variable. How to write the codes?
Thanks a lot!!! And I attach a screencut of my data.
data have;
input Year      GVKEY   $          total_pps       ;
cards;
1992      001045            50                  *
1993       001045           56                  6
1994       001045           99                  43
1995       001045           69                  -30
1996       001045           78                  9
1997       001045            88                 10
;
data want;
set have;
by gvkey year;
dif=dif(total_pps);
if first.gvkey then call missing(dif);
run;
Can you paste the date as text rather than pics plz . Also post a sample of your expected output plz
Sure. The attached is my expected output sample. Thank you!
data have;
input Year      GVKEY   $          total_pps       ;
cards;
1992      001045            50                  *
1993       001045           56                  6
1994       001045           99                  43
1995       001045           69                  -30
1996       001045           78                  9
1997       001045            88                 10
;
data want;
set have;
by gvkey year;
dif=dif(total_pps);
if first.gvkey then call missing(dif);
run;
Thanks a lot!! It works well!
@ADou Can you acknowledge the answer by marking as accepted and close the thread?
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.
