We have this dataset. There are only two items from the same store. And we want to determine items as new/old within the same store based on the year.
ID | YEAR | STORE |
100 | 2001 | 1 |
101 | 2003 | 1 |
102 | 1999 | 2 |
103 | 2004 | 2 |
104 | 2005 | 3 |
105 | 2007 | 3 |
This is the desired output
ID | YEAR | STORE | OLD_NEW |
100 | 2001 | 1 | OLD |
101 | 2003 | 1 | NEW |
102 | 1999 | 2 | OLD |
103 | 2004 | 2 | NEW |
104 | 2005 | 3 | OLD |
105 | 2007 | 3 | NEW |
To get the desired result use the proc sort procedure, then use first.store to get the new_items else old_items.
Please refer to code-
proc sort data=dt; by id year store; run;
proc sort data=dt; by store; run;
data dt1;
set dt;
by store;
if first.store then old_new = "New";
else old_new= "old";
run;
-Vijay
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.