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!!!!
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;
The code is:
data mergeddata;
merge datasetA (in=in1) datasetB (in=in2);
by country;
run;
Since you have a many-to-many relationship, and want a cartesian join, you need to use proc sql.
@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!!!!
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
With a data step, I have to
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.
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!
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.