0
votes

How can I create the following table with a more parsimonious data step than this PROC SQL query?

proc sql;  
insert into classdata
(t0avgStakeRank, eventtime, previousnode)                                                                                         
    values(0, 1, '')
    values(0, 2, 'L')
    values(0, 2, 'W')
    values(0, 3, 'LL')
    values(0, 3, 'LW')
    values(0, 3, 'WL')
    values(0, 3, 'WW')
    values(0, 4, 'LLL')
    values(0, 4, 'LLW')
    values(0, 4, 'LWL')
    values(0, 4, 'LWW')
    values(0, 4, 'WLL')
    values(0, 4, 'WLW')
    values(0, 4, 'WWL')
    values(0, 4, 'WWW')
    values(0, 5, 'LLLL')
    values(0, 5, 'LLLW')
    values(0, 5, 'LLWL')
    values(0, 5, 'LLWW')
    values(0, 5, 'LWLL')
    values(0, 5, 'LWLW')
    values(0, 5, 'LWWL')
    values(0, 5, 'LWWW')
    values(0, 5, 'WLLL')
    values(0, 5, 'WLLW')
    values(0, 5, 'WLWL')
    values(0, 5, 'WLWW')
    values(0, 5, 'WWLL')
    values(0, 5, 'WWLW')
    values(0, 5, 'WWWL')
    values(0, 5, 'WWWW')
    values(1, 1, '')
    values(1, 2, 'L')
    values(1, 2, 'W')
    values(1, 3, 'LL')
    values(1, 3, 'LW')
    values(1, 3, 'WL')
    values(1, 3, 'WW')
    values(1, 4, 'LLL')
    values(1, 4, 'LLW')
    values(1, 4, 'LWL')
    values(1, 4, 'LWW')
    values(1, 4, 'WLL')
    values(1, 4, 'WLW')
    values(1, 4, 'WWL')
    values(1, 4, 'WWW')
    values(1, 5, 'LLLL')
    values(1, 5, 'LLLW')
    values(1, 5, 'LLWL')
    values(1, 5, 'LLWW')
    values(1, 5, 'LWLL')
    values(1, 5, 'LWLW')
    values(1, 5, 'LWWL')
    values(1, 5, 'LWWW')
    values(1, 5, 'WLLL')
    values(1, 5, 'WLLW')
    values(1, 5, 'WLWL')
    values(1, 5, 'WLWW')
    values(1, 5, 'WWLL')
    values(1, 5, 'WWLW')
    values(1, 5, 'WWWL')
    values(1, 5, 'WWWW');                                                                                                                                                                                                                        
quit; 

This is the kind of stuff I would like to do:

DATA FOO;
DO t0avgStakeRank=0,1;
    DO eventtime=1,2,3,4,5;
            previousnode = cats(previousnode,'L');
            previousnode = cats(previousnode,'W');
            END;
        END;
END;
proc print;run;

It's being done in a macro, so I can't use DATALINES or CARDS.

1

1 Answers

1
votes

Take advantage of the fact that you're just replicating a binary progression but with different characters. TRANSLATE will fix the different character issue.

DATA FOO;
length previousnode $8;
DO t0avgStakeRank=0,1;
    DO eventtime=1 to 5;
        if eventtime=1 then do;
            previousnode=' ';
            output;
        end;
        else do;
            do _t = 0 to 2**(eventtime-1)-1;
                previousnode=translate(translate(trimn(putn(_t,'BINARY.',eventtime-1)),'L','1'),'W','0');
                output;
            end;
        end;
    END;    
END;
run;