How to read values separately off one variable that contains multiple information

Hello, I have a variable that includes multiple values, separated by commas. For example, I have a variable URBANICITY. For each subjects, I have values like this:

Urbanicity
Urban
Urban, Rural
Rural, Suburb
Suburb,
Urban, Rural, Suburb
***********

data old;
input Urbanicity $20.;
cards;
Urban
Urban, Rural
Rural, Suburb
Suburb
Urban, Rural, Suburb
;
run;

data temp;
set old;
numw=countw(urbanicity,',');
do i=1 to numw;
new_urban=scan(compress(urbanicity),i,',');
output;
end;
run;

proc print data=temp;
run;

proc freq data=temp;
tables new_urban;
run;
Thanks SAS!

Leave a Reply