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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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