These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
options mlogic sgen mprint;
/* Create sample data */
data work.ds1;
input a s d z $ x $ c $;
datalines;
1 . 3 qwe . yui
. . . . . hjk
3 . 3 zxc . .
;
/* Use SQL dictionary tables to create a list of character variables and a list
of numeric variables from the data set and store the result in macro variables
CLIST (character) and NLIST (numeric). The count of each type is also captured.
*/
proc sql noprint;
select name, put(count(name),5.-L) into :clist separated by ' ' , :charct
from dictionary.columns
where libname=upcase("WORK") and memname=upcase("DS1") and type='char';
select name, put(count(name),5.-L) into :nlist separated by ' ', :numct
from dictionary.columns
where libname=upcase("WORK") and memname=upcase("DS1") and type='num';
quit;
/* In a DATA _NULL_ create an array for the character variables and an array for the
numeric variables. Create two more arrays, one for character and one for numeric,
where the variables will serve as flags. The values are initially set to 'false'
to indicate that they have only missing values. Any time a non-missing values is
found for a variable, the corresponding flag variable is set to 'true'.
*/
/* Once the entire data set has been processed, loop through the flag arrays and
create a macro variable for any variable that still has a flag set to 'false'.
This will be the variables that will be kept when creating the NEW data set. */
data _null_;
array char(*) $ &clist;
array num(*) &nlist;
array c_allmiss (&charct) $ (&charct*'true');
array n_allmiss (&numct) $ (&numct*'true');
set DS1 end=done;
length keep $200;
retain keep;
do i=1 to dim(c_allmiss);
if char(i) ne ' ' then c_allmiss(i)='false';
if done and c_allmiss(i)='false' then keep=catx(' ',keep,vname(char(i)));
end;
do i=1 to dim(n_allmiss);
if num(i) ne . then n_allmiss(i)='false';
if done and n_allmiss(i)='false' then keep=catx(' ',keep,vname(num(i)));
end;
call symputx('keep',keep);
run;
data new;
set ds1(keep=&keep);
run;
proc contents;run;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Obs a d z c 1 1 3 qwe yui 2 . . hjk 3 3 3 zxc
Type: | Sample |
Topic: | SAS Reference ==> Procedures ==> SQL SAS Reference ==> DATA Step Common Programming Tasks ==> Utilities |
Date Modified: | 2013-02-15 10:52:31 |
Date Created: | 2004-09-30 14:08:58 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | All | n/a | n/a |