BookmarkSubscribeRSS Feed
ANKH1
Pyrite | Level 9

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.

IDYEARSTORE
10020011
10120031
10219992
10320042
10420053
10520073

 

This is the desired output

IDYEARSTOREOLD_NEW
10020011OLD
10120031NEW
10219992OLD
10320042NEW
10420053OLD
10520073NEW
3 REPLIES 3
Reeza
Super User
What determines an "item"? ID/Year are Unique and Store repeats twice each, I'm not sure your sample data adequately illustrates your problem. Can you add some more details about what you're trying to accomplish?

You can get the output shown by using FIRST/LAST but I don't think it will work with your actual data.


data want;
set have;
by store year;
if first.store then old_new = 'OLD';
if last.Store then old_new = 'NEW';
run;
ANKH1
Pyrite | Level 9
Yes, ID is each item and year is year of manufacturing. We want to determine within the same store, which item is older based on when manufacturing date (year).
vijaypratap0195
Obsidian | Level 7

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 617 views
  • 0 likes
  • 3 in conversation