I have a dataset that holds a number of rows of data about each Entity, the data is sorted in date order and I am using a programme to split the first record and the last record into their own tables. I then recombine these tables as one, with one row per entity and pairs of columns. This allows me to run comparisons and identify changes over time.
The code I use uses First and Last, which is dead simple, but I have a requirement to bring more data into my process, but to run the comparison over the same time period, so probably still First, but not Last anymore. I want to use a Prompt to define the row to select for the comparison, as I have different user groups that want to compare over different time periods.
My codes is:
data Earliest_Year;
set analysis;
by Customer;
if Last.Customer;
run;
How can I change "if Last.Customer;" to something like "If Offset(Last.Customer, -1*&Prompt)" if that makes sense?
Thanks!
How about sorting the data in reverse order?
proc sort data=Earliest_Year;
by descending Customer;
run;
data Earliest_Year;
set analysis;
by descending Customer;
if First.Customer then counter = 0;
counter + 1;
if counter = &prompt OR last.customer then .......[do your comparisons] ;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.