Hello
There is a row data file with 5 rows for each customer.
Requirements:
1- Create a new field called "PCT1" that calculate PCT change between each 2 consuctive rows for each customer (in X)
2- Create a new field called "Ind1" that get 3 possible values:
IF PCT1>50% then get value 1
IF PCT1<-50% then get value -1
else get value 0
3- Create a new field called "value_after_Increase"
that get value of varaible X when varaible PCT1 =1
4-Create a new field called "value_after_Deccrease"
that get value of varaible X when varaible PCT1 =-1
5-Create a new field called "Location" that get value of location (row number)
when varaible PCT1 =1
Data Raw_tbl;
input ID ddate X;
cards;
111 1905 10
111 1906 10
111 1907 10
111 1908 17
111 1909 17
222 1905 20
222 1906 20
222 1907 20
222 1908 20
222 1909 20
333 1905 15
333 1906 15
333 1907 27
333 1908 27
333 1909 15
;
run;
Use the lag() function for 1)
Everything else is simple if/then/else coding.
If 3, 4 and 5 are needed to create only a single row for each customer, retain your new variables, and use by-group processing to use last.id.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.