BookmarkSubscribeRSS Feed
sanjay1
Obsidian | Level 7

Hi Sas Experts,

 

I have two data sets: A and B.  I want to merge both the data sets on Country.

But the problem is the data set "A" Contains two digit country code and data set "B" contains three digit country code.

Is there is a way to convert two digit country code to three digit country code. Below is the data

 

DATA A;

Input country$ marks;

cards;

IND 20

USA 10

CAN 26

PHL 67

;

run;

 

Data b;

input Country$ subj$;

cards;

IN phy

US sci

CA math

PH bio

;

run;

 

Thanks & regards,

Sanjay

 

2 REPLIES 2
Reeza
Super User

Use SUBSTR() to convert the three charater to two character. 

 

Country_Code = substr(country_code, 1, 2);
GraphGuy
Meteorite | Level 14

You can use the isoalpha2 and isoalpha3 in mapsgfk.world_attr to do the mapping, something like this ...

 

proc sql;

 

create table a as
select unique a.*, world_attr.isoalpha2
from a left join mapsgfk.world_attr
on a.country=world_attr.isoalpha3;

 

create table a as
select unique a.*, b.subj
from a left join b
on a.isoalpha2=b.country;

 

quit; run;

 

 

Obs country marks ISOALPHA2 subj
1 CAN 26 CA math
2 IND 20 IN phy
3 PHL 67 PH bio
4 USA 10 US sci

 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 3538 views
  • 2 likes
  • 3 in conversation