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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 803 views
  • 0 likes
  • 3 in conversation