BookmarkSubscribeRSS Feed
SanKH1
Quartz | Level 8

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;
SanKH1
Quartz | Level 8
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 2024

Innovate_SAS_Blue.png

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. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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