DATA Step, Macro, Functions and more

how to create new column in dataset and define continent based on country column

Reply
Occasional Learner
Posts: 1

how to create new column in dataset and define continent based on country column

Dear All , 

               

 I have column(Retailer_country) and its holding values (us,china,india,japan) now i want to identify the continent of each country 

 which it belongs to , And save it in  a new column.

 

.This is my first sas post , Can Any one help me how i can i do this..

 

 

 

 

PROC Star
Posts: 172

Re: how to create new column in dataset and define continent based on country column

Welcome to SAS forum. Typical example of a case where you would use Proc format aka user defined format and use a put function or format statement in a datastep to apply that format. 

Super User
Posts: 17,829

Re: how to create new column in dataset and define continent based on country column

See if you have access to the SASMAPS library on your computer. One of the datasets in there will have the mapping of countries to continents and you can use that to do the lookup.

Super User
Posts: 10,500

Re: how to create new column in dataset and define continent based on country column

If you have a MAPSGFK library installed the data set Maps.gfk.World_attr has country names and a numeric code 91 to 97 for continent.

Frequent Contributor
Posts: 125

Re: how to create new column in dataset and define continent based on country column

Hi,

 

MAPSGFK is a Library in SAS that comes with the SAS product installation(Most cases). In this Library you can find WORLD_ATTR tabel where you can find most of the well known countries with continent code. Here is my sample code( make sure the values are case-sensitive so the contries names has to be all upcase)

data country;
infile datalines;
input country $15.;
datalines;
INDIA
CHINA
UNITED STATES
JAPAN
;
RUN;
/* 91-North America, 92-South America, 93-Europe, 94-Africa, 95-Asia, 96-South Pacific. */
PROC FORMAT ;
VALUE Cont  91="North America"
            92="South America"
												93="Europe"
												94="Africa"
												95="Asia"
												96="South Pacific";
RUN;

PROC SQL;
   CREATE TABLE WORK.QUERY_FOR_COUNTRY AS 
   SELECT t1.country, 
          t2.CONT format=cont.
      FROM WORK.COUNTRY t1
           INNER JOIN MAPSGFK.WORLD_ATTR t2 ON (t1.country = t2.ISONAME);
QUIT;

Thanks,

Suryakiran

Thanks,
Suryakiran
Ask a Question
Discussion stats
  • 4 replies
  • 80 views
  • 1 like
  • 5 in conversation