BookmarkSubscribeRSS Feed
aidant01
Fluorite | Level 6

Hi All, 

 

I'm trying to get the desired dataset with the following command

 

data wanted;

merge dataA (in=in1) dataB (in=in2);

by Country, 

run;

 

But with no luck. any help is appreciated! Thanks!!!!

5 REPLIES 5
Shmuel
Garnet | Level 18

You have not supplied your log nor explained what issue you have.

I suspect that one or both of your data sets are not sorted  properly.

Both should be sorted by same key - country - in your case:

proc sort data=dataA; by country; run;
proc sort data=dataB; by country; run;

data wanted;
merge dataA (in=in1) dataB (in=in2);
by Country; /* you had a comma instead a semicolon */ 
run;
aidant01
Fluorite | Level 6

 

The code is:

 

data  mergeddata;

merge datasetA (in=in1) datasetB (in=in2);

by country;

run;

 

 

Screen Shot 2018-12-02 at 1.00.51 PM.png

 

PGStats
Opal | Level 21

@aidant01 wrote:

Hi All, 

 

I'm trying to get the desired dataset with the following command

 

data wanted;

merge dataA (in=in1) dataB (in=in2);

by Country; 

run;

 

But with no luck. any help is appreciated! Thanks!!!!


 

PG
Kurt_Bremser
Super User

Maxim 2: Read the Log.

Which implies that it is always a good idea to post the log when steps do not work as expected, as it allows us to interpret your log, find the problem, and show you how to interpret SAS logs. Reading and getting information from the log is an essential SAS skill.

 

Also do not provide data in Excel spreadsheets; spreadsheets have no structure like datasets, and it's never given that the re-import into SAS results in a dataset like yours. Post example data in a data set with datalines.

With Excel, I need to

  • download the spreadsheet
  • open it with Excel to save as csv
  • copy the csv to the server
  • run proc import or a data step, while making guesses about the structure

With a data step, I have to

  • copy paste to a code window
  • submit the code

and there are no ambiguities with regards to structure.

 

The macro from one of my footnotes can do the conversion of a dataset to a data step automatically.

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
  • 5 replies
  • 897 views
  • 0 likes
  • 4 in conversation