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

Hello,

I have 2 different datasets. Dataset 1 has about 500 observations and 15 variables and Dataset 2 has 7500 observations and 250 variables.

I have to import that 250 variables from Dataset 2 for that 500 observations in Dataset 1 (note 500 observations in dataset 1 are present in dataset 2 by three common identifiers: last name, first name and IDnumber)

If I use a

merge dataset1 dataset2; by firstname lastname IDnumber;

I am thinking I am going to get 7500 observations with 500 of them having that 15 extra variables (-3 common identifiers) from dataset 1.

Any idea how else I could use to merge this and just have a new combined dataset that has 500 observations from Dataset with 15 + 250 variables ?

Your help is much appreciated !!!

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

You just need an extra statement:

merge dataset1(in=inD1) dataset2; by firstname lastname IDnumber;

if inD1;


PG

PG

View solution in original post

3 REPLIES 3
Venki
Calcite | Level 5

Figured it out myself.

Just a simple delete command for a variable thats only present in dataset 1 but not in dataset2 by writing

if variable =' ' then delete;

worked like a charm

Just a little extra thinking that I was lacking when initially thinking about it.

Thanks anyways for folks reading this !

PGStats
Opal | Level 21

You just need an extra statement:

merge dataset1(in=inD1) dataset2; by firstname lastname IDnumber;

if inD1;


PG

PG
Venki
Calcite | Level 5

Thanks so much. Thats really good to know !

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 569 views
  • 0 likes
  • 2 in conversation