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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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