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
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;
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
;
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??
Ok. They are in a single variable, correct?
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;
Thank you so much!! It is exactly what I need!!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.