BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ADou
Calcite | Level 5

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.

微信图片_20190109144939.png

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

Can you paste the date as text rather than pics plz . Also post a sample of your expected output plz

ADou
Calcite | Level 5

Sure. The attached is my expected output sample. Thank you!

novinosrin
Tourmaline | Level 20

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;
ADou
Calcite | Level 5

Thanks a lot!! It works well! 

Allaluiah
Quartz | Level 8

@ADou  Can you acknowledge the answer by marking as accepted and close the thread?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1212 views
  • 0 likes
  • 3 in conversation