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!!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.