BookmarkSubscribeRSS Feed
jap6198
Calcite | Level 5

Hello,

I am trying to calculate the percent change in Assets_Total between year 2018-2019 over various companies. Please help! 

example: 

Permno Company Date Assets_Total 
111xx1/2/181
111xx1/2/192
222yy1/2/183
222yy1/2/194
333zz1/2/185
333zz1/2/196

 

what I want: 

Permno Company Date Assets_Total pcnt change
111xx1/2/181-
111xx1/2/1921
222yy1/2/183-
222yy1/2/1940.33333333
333zz1/2/185-
333zz1/2/1960.2

 

THANK YOU!!! 

@PaigeMiller

 

1 REPLY 1
mkeintz
PROC Star

 

data want;
set have;
by permno;
pctn_change=dif(assets_total)/lag(assets_total);
if first.permno then pctn_change=.;
run;

The DIF function is defined as  DIF(x) ==   x-LAG(x).

 

The SET with a BY statement provides a dummy to identify when the record in hand is the start (first.permno) or end (last.permno) of a sequence of records with the same permno.  So the IF statement sets pctn_change to missing to prevent contamination from the prior permno.

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 332 views
  • 0 likes
  • 2 in conversation