I have a dataset in SAS that has 10 variables on the basis of which I would like to create a new flag. If any of the class columns is greater than 0 then its name should come in the flag as given in the picture below.
Can someone please help me on how this can be done?
Thanks
Try this
data have;
input ID Class_Tom Class_Sim Class_Sam Class_Jack Class_Des Class_Pun Class_Jun Class_Kick Class_Pop Class_Neo;
infile datalines dlm = '|' dsd;
datalines;
101|95| | | | | | | | |
102|82| |27| | | | | | |
103| |56| | | |61| |80| |
104| | | | | | | | | |
;
data want(drop = i);
set have;
array c{*} class_:;
length flag $200;
flag = '';
do i = 1 to dim(c);
if c[i] then flag = catx(' | ', flag, vname(c[i]));
end;
run;