[last updated - 31 July 2003]
Displays a list of all-missing variables. You can specify a single dataset, multiple datasets or leave it blank and it will run on the whole library. This is a very useful QC tool as all-missing variables should be rare. Note that the SAS code within it requires some of the sasautos extensions macros on this web site.
#!/bin/sh # Script : allmiss # Version : 1.0 # Author : Roland Rashleigh-Berry # Date : 31 July 2003 # Contact : roland@rashleigh-berry.fsnet.co.uk # Purpose : List all-missing variables # SubScripts : none # Notes : Uses the sasautos extensions macros. You need to make sure these # are available on the sasautos path. # Usage : allmiss ds1 ds2 # allmiss #================================================================================ # PARAMETERS: #-pos- -------------------------------description-------------------------------- # 1 (optional) dataset or list of datasets to check for all-missing variables. # Defaults to the whole library. #================================================================================ # AMENDMENT HISTORY: # init --date-- mod-id ----------------------description------------------------- # #================================================================================ # check on the existence of a sas program in the home directory if [ -f $HOME/allmiss.sas ] ; then echo "SAS program allmiss already exists in your home directory. You need to check" 1>&2 echo "if you need it and delete it if not. This utility will not overwrite it and" 1>&2 echo "will now exit." 1>&2 exit 1 fi if [ $# -eq 0 ] ; then ############ no parameters specified so do for whole library ############ # Write SAS code out to a temporary file cat > $HOME/allmiss.sas << END options validvarname=any nofmterr; libname here './' access=readonly; filename _outfile "$HOME/allmiss.tmp"; %dslist(here) %macro doit; %do i=1 %to %words(&_dslist_); %let memname=%scan(&_dslist_,&i,%str( )); %missvars(here.&memname) %if %length(&_miss_) %then %do; data miss; length memname $ 8 varname $ 20; retain memname "&memname"; %do j=1 %to %words(&_miss_); varname="%scan(&_miss_,&j,%str( ))"; output; %end; run; proc append base=base data=miss; run; %end; %end; data _null_; file _outfile notitle noprint; set base; put @1 memname @10 varname; run; %mend doit; %doit END # Run the SAS code sas -log "$HOME" -sysin "$HOME/allmiss.sas" # Delete the temporary SAS code and optionally the log rm -f $HOME/allmiss.sas # $HOME/allmiss.log # If output file exists then cat it and delete it if [ -f $HOME/allmiss.tmp ] then cat $HOME/allmiss.tmp rm -f $HOME/allmiss.tmp fi else for dataset in "$@" ; do ########## do for individual specified datasets ########## # Write SAS code out to a temporary file cat > $HOME/allmiss.sas << END options validvarname=any nofmterr; libname here './' access=readonly; filename _outfile "$HOME/allmiss.tmp"; %macro doit; %missvars(here.$dataset) %if %length(&_miss_) %then %do; data miss; length memname $ 8 varname $ 20; retain memname "&memname"; %do j=1 %to %words(&_miss_); varname="%scan(&_miss_,&j,%str( ))"; output; %end; run; %end; %mend doit; %doit data _null_; file _outfile notitle noprint; set miss; put @1 "%upcase($dataset)" @10 varname; run; END # Run the SAS code sas -log "$HOME" -sysin "$HOME/allmiss.sas" # Delete the temporary SAS code and optionally the log rm -f $HOME/allmiss.sas # $HOME/allmiss.log # If output file exists then cat it and delete it if [ -f $HOME/allmiss.tmp ] then cat $HOME/allmiss.tmp rm -f $HOME/allmiss.tmp fi done fi
Go back to the home page.
E-mail the macro and web site author.