BookmarkSubscribeRSS Feed
tyq1992
Calcite | Level 5

Hi all,

 

I have two different datasets, 1 containing country and continent information and the other 1 containing continent and profit ratios.

 

Dataset 1:

Country          Continent

China              Asia

Japan             Asia

Malaysia         Asia

Germany        Europe

Australia         Oceania

 

Dataset 2:

Continent          Profit_Margin

Asia                  0.05

Europe             0.08

America            0.02

 

My desired results are:

Country          Continent         Profit_Margin

China              Asia                 0.05

Japan             Asia                  0.05

Malaysia         Asia                 0.05

Germany        Europe            0.08

Australia         Oceania          .

 

Have tried the following code:

Data want;

merge Dataset_1 (IN=A) Dataset_2 (IN=B);

by Continent;

If A;

 

But the results i get are:

 

Country          Continent         Profit_Margin

China              Asia                 0.05

Japan             Asia                  .

Malaysia         Asia                 .

Germany        Europe            0.08

Australia         Oceania          .

 

Appreciate any advice i could get on this. Thanks in advance!

 

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

1. Your code if fine is the data is sorted and works are desired

2. Your second data set is not sorted.

3. What do you have on your log?

tyq1992
Calcite | Level 5

Thanks.

 

Have sorted the second dataset by continent. It now appears as:

 

Dataset 2:

Continent          Profit_Margin

America            0.02

Asia                  0.05

Europe             0.08

 

Still facing the same problem though.

 

Log seems fine. It reads:

"There were 5 obs read from data set work.want"

 

gamotte
Rhodochrosite | Level 12

Hello,

 

You'll have to give more details than that because your code works fine :

 

 

data Dataset_1;
    length Country Continent $10;
    input Country $ Continent $;
    cards;
China Asia
Japan Asia
Malaysia Asia
Germany Europe
Australia Oceania
;
run;

data Dataset_2;
    length Continent Profit_Margin $10;
    input Continent $ Profit_Margin $;
cards;
Asia 0.05
Europe 0.08
America 0.02
;
run;

proc sort data=Dataset_1; by Continent; run;
proc sort data=Dataset_2; by Continent; run;

data want;
merge Dataset_1 (IN=A) Dataset_2 (IN=B);
by Continent;
if A;
run;

 Can you give the complete log for the data step ?

 

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 628 views
  • 0 likes
  • 3 in conversation