BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
cosmid
Lapis Lazuli | Level 10

Hi,

 

If I have two datasets, One and Two, both has a column named ID, how do I replace One's ID with Two's ID for just first 10 observations, ignoring all other vars?

 

Thanks!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Sounds like crazy thing to do.

data want;
  merge one two(keep=id obs=10);
run;

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

Sounds like crazy thing to do.

data want;
  merge one two(keep=id obs=10);
run;
cosmid
Lapis Lazuli | Level 10

Oops...it seems that method didn't work. Instead of replacing the first 10 IDs it added 10 rows with the CMIDs fro the second dataset Two to the first dataset, One. 

cosmid
Lapis Lazuli | Level 10

It worked. I am an idiot. For some reason I used SET instead of MERGE. Sorry for spamming.

 

Thanks for the help!

Tom
Super User Tom
Super User

If you want to use SET then add an IF statement.

data want;
  set one;
  if _n_ <= 10 then set two(keep=id);
run;
cosmid
Lapis Lazuli | Level 10

Wow! Thanks! It would be nice if I can do that with SAS. A MERGE with and without BY confuses me enough, lol. I need to get more practice for sure. Thanks again for teaching me the trick with the use of SET!

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!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 593 views
  • 2 likes
  • 2 in conversation