BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Phil_from_PGA
Calcite | Level 5

Hello, I'm using SAS University edition / SAS studio.

I have two datasets with three variables item ID; quantity and price. The first data set has item ID and a unique quantity for that item. The second data set has item ID and price for that item - but the item ID and (same) price appear several repeated times.  

I just want a merged data set that has: item ID, quantity and one (same) price as the columns. How do I do this?

For example, see the code below:

 

/* Create sample data */
data one;
 input id $ quantity $;
 datalines;
Item_a 4
Item_b 3
Item_c 2;

 

data two;
 input id $ price $;
 datalines;
Item_a 1.10
Item_a 1.10
Item_b 2.35
Item_b 2.35
Item_c 5.50
Item_c 5.50
Item_c 5.50;

 

data both;
 merge one (in=in1) two (in=in2);
 by id;

 if in1=1 and in2=1;
run;

proc print data=both;
run;

  

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Why does the second data set have duplicates? I would remove the duplicates and then merge. Your data step code will work. You can remove duplicates with proc sort and noduprecs or nodupkey. 

View solution in original post

2 REPLIES 2
Reeza
Super User

Why does the second data set have duplicates? I would remove the duplicates and then merge. Your data step code will work. You can remove duplicates with proc sort and noduprecs or nodupkey. 

Phil_from_PGA
Calcite | Level 5
Thanks - that worked well.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

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
  • 2 replies
  • 2520 views
  • 1 like
  • 2 in conversation