how do i divide an observation in rows by a string?

I’ve not coded in SAS for a while but this seems to work fine:

data have;
    length ID $8 p1 $2 p2 $2 p3 $2 p4 $2 list $100;
    infile cards dsd dlm='|' truncover;
    input ID p1 p2 p3 p4 list;
    cards;
120265|.|.|.|25|a t 90%, b r 10%
120267|15|15|15|15|c e 80%, a 20%
120269|20|20|20|20|cc
;

data col2rows;
    set have;
    length perc $10;

    do i=1 by 1 until (perc=' ');
        perc=strip(scan(list, i, ','));

        if perc ne ' ' then
            output;
    end;
run;

data want;
    set col2rows (drop=list i);
run;

Which prints out as expected:

enter image description here

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top