data t;
input sno category$ 20.;
cards;
1 dairy floor eggs
2 floor milk
3 eggs bread
4 bread butter butter
;run;
i have this data set and i want distinct category (dairy,floor,eggs,milk,bread,butter).
I can do like this
data t1;
set t;
do i=1 to 3;
x=scan(category,i);
output;
end;
run;
proc print;run;
but here i dnt knw how many times i have to run the loop like 3 or 4 or 5 times.Any optimum way?
data t1;
set t;
do i=1 to countw(category);
x=scan(category,i);
output;
end;
run;
Read the categories one by one until the end of each line:
data t;
infile datalines truncover;
input sno category :$20. @;
do until(missing(category));
output;
input category :$20. @;
end;
datalines;
1 dairy floor eggs
2 floor milk
3 eggs bread
4 bread butter butter
;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.