BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASUser0001
Fluorite | Level 6
data want;

set a;

rel_diff=abs((amount1-amount2)/amount1);



format rel_diff percent5.0;

run;

</>

 

hi The following program shows between two variables but I am looking to get percentage change between two number in a variable.

 

my data is like this

date Range

31-Mar-80 1800

30-Jun-80 1300

30-Sep-80 800

31-Dec-80 300

31-Mar-81 600

30-Jun-81 900

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Use the DIF and LAG functions to refer to the previous value:

 

data want;
set a;
rel_diff = abs( dif(range) / lag(range) );
format rel_diff percent5.0;
run;
PG

View solution in original post

1 REPLY 1
PGStats
Opal | Level 21

Use the DIF and LAG functions to refer to the previous value:

 

data want;
set a;
rel_diff = abs( dif(range) / lag(range) );
format rel_diff percent5.0;
run;
PG

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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