Hi,
I have a data set "world" which include 256 countries and continent. And another data set "have" include 125 countries and other variable. Now I want to attach the continent information to data"have".
So my code is
proc sort data=world;
by country;
run;
proc sort data=have;
by country;
run;
data attached;
merge have world;
by country;
run;
And the result is something like
country variables continent
1 Armenia 22 .
2 China 15 .
3 Korea 5 .
...
126 Armenia . Asia
127 China . Asia
128 Korea . Asia
What I want is
country variables continent
1 Armenia 22 Asia
2 China 15 Asia
3 Korea 5 Asia
...
Does my code have problem ?? Anyone could modify my code to get what I want?
THANK YOU
I have found a solution with using the strip function to remove the leading blank. So SAS can recognize two countries variables are the same and the merge would work.
It looks like the country names don't really match. Maybe you have invisible characters (tabs?) or leading spaces as part of the country names in one of the datasets.
I checked the output data and I did not see the countries have leading space(for both of them). How should I modify my code to solve this problem??
Thank you
Have you checked if your country variable has a format?
you can run a proc contents to see that as follows :
proc contents data= have ;
run;
proc contents data= world ;
run;
I don't think they have a format. What format they are supposed to have? How should I add a format to them?
@YangYY wrote:
I don't think they have a format.
Don't think. KNOW. Run proc contents. This will reveal types, lengths and formats.
If you do a join or merge on character variables, they must have identical values. This means the join is case-sensitive.
How did you inspect your columns? The best way to find erratic characters is to create a new variable where you store the hex coding.
Suppose your country column has a length of 10, then do this (in both datasets):
length country_hex $20;
country_hex = put(country, $hex20.);
Then you can have a very clear picture of the contents.
I have found a solution with using the strip function to remove the leading blank. So SAS can recognize two countries variables are the same and the merge would work.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.