In: Statistics and Probability
In SAS, how do I extract the city, state, and zipcode into separate columns from a single variable with all three?
Example-
Bremen, KS, 66412
Little River, KS, 67457
Bird City, KS, 67731
The above is stored in one variable each. But I want to make three separate variables with it. Some cities also have two words in it.
Solution-
Programm In SAS
/*Read the data and store in one datasets*/
data test;
infile cards dlm=',';
input City $ : 12. State $ Zipcode;
cards;
Bermen,KS,66412
Littel River,KS,67457
Bird City,KS,67731
;
/*Extarct variables one by one and store in
datasets*/
/*Extact City*/
data City;
set Test(keep=City);
run;
/*Extact State*/
data State;
set Test(keep=State);
run;
/*Extarct Zipcode*/
data Zipcode;
set Test(keep=Zipcode);
run;
/*print the data*/
proc print data=test;
run;
proc print data=city;
run;
proc print data=state;
run;
proc print data=Zipcode;
run;
Output of the program