Try this, Beate DATA Have; INPUT ID A B C D E; CARDS; 101 1 1 . . 1 102 . . 1 . . 103 1 1 . . . RUN; /* collect contents of your data set and use it to generate a macro variable that has all names different from ID in your data set macro variable varlist has all names of variables in your data set, macro variable nvar has the number of variables in your data set note there are other ways of doing the same thing, e.g., PROC SQL ... */ PROC CONTENTS DATA=have NOPRINT OUT=cntnts (KEEP=name WHERE=(UPCASE(name) NE 'ID')); RUN; DATA _NULL_; LENGTH varlist $ 512; /* need to make sure to make long enough to accommodate the length of all your variable names strung together */ RETAIN varlist " " nvar 0; SET cntnts END=lastobs; nvar + 1; varlist = TRIM(LEFT(varlist))||" "||COMPRESS(name); IF lastobs THEN DO; CALL SYMPUT('varlist',TRIM(LEFT(varlist))); CALL SYMPUT('nvar',COMPRESS(nvar)); END; RUN; /* need to use a macro as %do are not allowed outside of macros; I am not sure what is important the variable being 1 or the variable being missing; the code checks for the variable being missing, need to change as you need it */ %MACRO quick; DATA havenew; SET have; ARRAY _newcols {&nvar} $ 1 col1-col&nvar; /* might have to change length here to the maximum possible length of your variable names */ j=0; %DO i=1 %TO &nvar; %LET thisvar=%SCAN(&varlist,&i); IF MISSING(&thisvar) EQ 0 THEN DO; j=j+1; _newcols{j}="&thisvar"; END; %END; DROP j; RUN; %MEND quick; %quick; OPTIONS NOCENTER; PROC PRINT NOOBS; RUN; ID A B C D E col1 col2 col3 col4 col5 101 1 1 . . 1 A B E 102 . . 1 . . C 103 1 1 . . . A B
... View more