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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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