proc sql; create table test (myID num, myOne varchar(5), myTwo num, myThree varchar(5), myFour num, myFive num, mySix varchar(5)); insert into test values(1, '', null, '3', 4, 5, '6'); insert into test values(2, '1', null, '3', 4, 5, ''); insert into test values(3, '', 2, '3', null, 5, ''); insert into test values(4, '1', 2, '3', null, 5, '6'); insert into test values(5, '1', 2, '3', 4, 5, ''); quit; /* This will give you the user id along with a string containing the name of each colum that was missing or null. colum list is in a funky order because of using two seperate arrays. */ data myOut (replace=yes compress=no); set test; array myChar _CHARACTER_; array myNum _NUMERIC_; myFlag = 0; length myMissing $ 300; length myMissingOne $ 300; do _i=1 to dim(myChar); if(myChar[_i] = '') then do; myMissingOne = VNAME(myChar[_i]); myMissing = catx(' ', myMissing, myMissingOne); myFlag=1; end; end; do _i=1 to dim(myNum); if(myNum[_i] = .) then do; myMissingOne = VNAME(myNum[_i]); myMissing = catx(' ', myMissing, myMissingOne); myFlag = 1; end; end; if(myFlag = 1) then output; keep myID myMissing; run; /* This will give you a dataset listing all of the columns that contain either null or missing. The columns are tied to the client ID through a one to many relationship in this table. One client ID and many columns. The client ID/Column relation is unique. */ data myOutTwo (replace=yes compress=no); set test; array myChar _CHARACTER_; array myNum _NUMERIC_; myFlag = 0; length myMissing $ 300; do _i=1 to dim(myChar); if(myChar[_i] = '') then do; myMissing = VNAME(myChar[_i]); output; end; end; do _i=1 to dim(myNum); if(myNum[_i] = .) then do; myMissing = VNAME(myNum[_i]); output; end; end; keep myID myMissing; run;
... View more