Create dummy variables SAS

Solution 1:

Good start but not sure why you switched to macro logic halfway through.

First take your data set and create a new row for each letter attached to the ID instead of trying to deal with it in the current structure.

Then use PROC FREQ which will generate that table above but not in a data set. The data set will need to be restructured if you want it in that output. For that step, use PROC TRANSPOSE to get your final structure.

DATA long;
    SET dummified_dataset;
    DO i = 1 TO COUNTW(text, ",");
        var_text = SCAN(text, i, ",");
       output;
    END;
RUN;

proc freq data=long;
table id*var_text / out=long_freq sparse nopercent nocol norow;
run;

proc transpose data=long out=long_freq;
by id;
id var_text;
var count;
run;