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.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

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
  • 856 views
  • 2 likes
  • 2 in conversation