BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
YangYY
Quartz | Level 8

Hi,

 

I got a column is cities which is like

 

cities

Saint Petersburg,Russia

Istanbul,Turkey

Porto Alegre,Brazil

Izmir,Turkey

Helsinki,Finland

 

And I have another document which includes country and continent. I want to attach the continent of each city. But I think I need to extract the country from the cities above and I use proc sort to merge them with the document. But I have no idea how to extra some information from a column(maybe I should use delimiter "," ?)

 

Anyone could help me with that?? Or do it in another way??

Thank you so much in advance

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

See if this helps you

 

data have;
input cities $ 1-100;
infile datalines truncover;
datalines;
Saint Petersburg,Russia
Istanbul,Turkey
Porto Alegre,Brazil
Izmir,Turkey
Helsinki,Finland
;

data want;
    set have;
    city=scan(cities, 1, ',');
    country=scan(cities, 2, ',');
run;

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

Like this?

 

data have;
input city :$20. country :$20.;
infile datalines dlm=',';
datalines;
Saint Petersburg,Russia
Istanbul,Turkey
Porto Alegre,Brazil
Izmir,Turkey
Helsinki,Finland
;
YangYY
Quartz | Level 8
Saint Petersburg,Russia
Istanbul,Turkey
Porto Alegre,Brazil
Izmir,Turkey
Helsinki,Finland

 Thanks for your reply. But these cities above are included in a column of a data set.  So how can I use infile statement??

PeterClemmensen
Tourmaline | Level 20

Ok. They are in a single variable, correct?

YangYY
Quartz | Level 8
yes,they are
PeterClemmensen
Tourmaline | Level 20

See if this helps you

 

data have;
input cities $ 1-100;
infile datalines truncover;
datalines;
Saint Petersburg,Russia
Istanbul,Turkey
Porto Alegre,Brazil
Izmir,Turkey
Helsinki,Finland
;

data want;
    set have;
    city=scan(cities, 1, ',');
    country=scan(cities, 2, ',');
run;
YangYY
Quartz | Level 8

Thank you so much!! It is exactly what I need!!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1794 views
  • 0 likes
  • 2 in conversation