printalln

[last updated - 31 July 2003]

This utility prints all the information it can find in a library that satisfies a condition on a numeric variable. You would typically use this to print out all information for a subject if "subject" were a numeric variable like this printall subject=1234. Output goes to the terminal window by default as always. It is up to the user to redirect if required.


#!/bin/sh
# Script     : printalln
# Version    : 1.0
# Author     : Roland Rashleigh-Berry
# Date       : 31 July 2003
# Contact    : roland@rashleigh-berry.fsnet.co.uk
# Purpose    : To print out all records in a library that satisfy a condition on
#              a numeric variable 
# SubScripts : none
# Notes      : Make the data directory the current directory. Output goes to
#              terminal window by default.
# Usage      : printalln subject=1234
# 
#================================================================================
# PARAMETERS:
#-pos- -------------------------------description--------------------------------
#  1   condition on numeric variable
#================================================================================
# AMENDMENT HISTORY:
# init --date-- mod-id ----------------------description-------------------------
# 
#================================================================================

# Put out a usage message if not enough parameters supplied
if [ $# -lt 1 ] ; then
  echo "Usage: printalln subject=1234" 1>&2
  exit 1
fi

# check on the existence of a sas program in the home directory
if [ -f $HOME/printalln.sas ] ; then
  echo "SAS program printalln 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

# Write SAS code out to a temporary file
cat > $HOME/printalln.sas << END
options validvarname=any nofmterr formdlim='-' symbolgen;
libname here './' access=readonly;
filename _outfile "$HOME/printalln.tmp";
%let variable=%scan($1,1,^=<>%str( ));
proc printto print=_outfile;
run;
data _null_;
  set sashelp.vcolumn(where=(libname="HERE" and name="&variable"));
  call execute('proc print data='||trim(libname)||'.'||trim(memname)||'(where=($1));
  title "$1 - ALL DATA FOR '||trim(libname)||'.'||trim(memname)||'";run;');
run;
END


# Run the SAS code
sas -log "$HOME" -sysin "$HOME/printalln.sas"


# Delete the temporary SAS code and optionally the log
rm -f $HOME/printalln.sas # $HOME/printalln.log 


# If output file exists then cat it and delete it
if [ -f $HOME/printalln.tmp ]
then
  cat $HOME/printalln.tmp
  rm -f $HOME/printalln.tmp
fi

Go back to the home page.

E-mail the macro and web site author.