/**********************************************************************/ /* This code creates the LAKES data set. */ data lakes; input month $ L1_a $ L1_b / @11 L2_a $ L2_b / @11 L3_a $ L3_b / @11 L4_a $ L4_b / @11 L5_a $ L5_b / @11 L6_a $ L6_b; cards; march95 high . high .86 . .45 medium .88 low .96 . .45 april95 high . low .54 . .75 low .98 medium .94 . .67 may95 high . . .32 . .43 low 1.40 medium .75 . .68 june95 low . medium 1.5 . 1.2 high 1.5 medium .86 . .62 july95 medium . medium 1.32 . 1.00 high . medium 1.30 . .70 aug95 medium . low .87 . . medium .43 low 1.8 . .91 sep95 medium . medium .43 . .94 low .65 low .90 . .59 ; options nodate nonumber ls=132; proc print data=lakes noobs; title "LAKES Data Set"; run; /**********************************************************************/ /* This is the code for the DROPVAR macro. */ %macro dropvar(dsn,typ); %local total ccount ncount exist; %let total=0; %let ccount=0; %let ncount=0; %let typ=%upcase(&typ); %if &dsn ne %then %do; data _null_; if 0 then set &dsn; stop; run; %end; %if &syserr=0 %then %let exist=YES; %else %let exist=NO; %if &exist=YES and (&typ=N or &typ=C or &typ=B) %then %do; proc contents data=&dsn out=_tmp_(keep=type nobs) noprint; data _null_; set _tmp_ end=eof; if nobs=0 then stop; if type=1 then num+1; else char+1; if eof then do; call symput('ncount',trim(left(put(num,8.)))); call symput('ccount',trim(left(put(char,8.)))); end; proc datasets nolist; delete _tmp_; quit; data _null_; set &dsn end=eof; %if &ccount ne 0 %then %do; array chars(*) _character_; %end; %if &ncount ne 0 %then %do; array nums(*) _numeric_; %end; length temp $8; %if (&typ=C or &typ=B) and &ccount ne 0 %then %do; array charchek(*) $1 _c_1 - _c_&ccount; retain _c_1-_c_&ccount; do i=1 to dim(chars); if chars(i) ne ' ' then charchek(i)='X'; end; if eof then do; do i=1 to dim(chars); if charchek(i) ne 'X' then do; c+1; call vname(chars(i),temp); call symput('_v'||trim(left(put(c,8.))),trim(temp)); end; end; call symput('total',trim(left(put(c,8.)))); end; %end; %if (&typ=N or &typ=B) and &ncount ne 0 %then %do; array numchek(*) $1 _n_1 - _n_&ncount; retain _n_1-_n_&ncount; do i=1 to dim(nums); if nums(i) ne . then numchek(i)='X'; end; if eof then do; do i=1 to dim(nums); if numchek(i) ne 'X' then do; c+1; call vname(nums(i),temp); call symput('_v'||trim(left(put(c,8.))),trim(temp)); end; end; call symput('total',trim(left(put(c,8.)))); end; %end; run; %if &total ne 0 %then %do; data &dsn; set &dsn(drop= %do i=1 %to &total; &&_v&i %end; ); run; %end; %put; %put NOTE: Macro DROPVAR removed &total variable(s) from data set.; %put; %end; %else %do; %put; %put ERROR: Execution of macro DROPVAR terminated due to invalid; %put %str( parameter values.); %put; %put %str( Data Set Name = %upcase(&dsn)); %put %str( Variable Type = &typ); %put; %end; %mend dropvar; /**********************************************************************/ /* This code invokes the DROPVAR macro. */ %dropvar(lakes,b) /**********************************************************************/