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
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.