This utility prints all the information it can find in a library that satisfies a condition on a character variable. You would typically use this to print out all information for a subject if "subject" were a characterc 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 : printallc
# Version : 1.0
# Author : Roland Rashleigh-Berry
# Date : 31 July 2003
# Contact : rolandberry@hotmail.com
# Purpose : To print out all records in a library that satisfy a condition on
# a character variable
# SubScripts : none
# Notes : Make the data directory the current directory. Output goes to
# terminal window by default.
# Usage : printallc 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: printallc subject='1234' " 1>&2
exit 1
fi
# check on the existence of a sas program in the home directory
if [ -f $HOME/printallc.sas ] ; then
echo "SAS program printallc 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/printallc.sas << END
options validvarname=any nofmterr formdlim='-';
libname here './' access=readonly;
filename _outfile "$HOME/printallc.tmp";
%let variable=%scan($1,1,^=<>);
%put >>>>>> variable=&variable;
%let value=%scan($1,2,^=<>:);
%put >>>>>> value=&value;
%let op=%substr($1,%sysfunc(indexc(%quote($1),^=<>)),%eval(%length($1)-%length(&variable)-%length(&value)));
%put >>>>>> op=&op;
%let value="&value";
proc printto print=_outfile;
run;
data _null_;
set sashelp.vcolumn(where=(libname="HERE" and upcase(name)=upcase("&variable")));
call execute('proc print data='||trim(libname)||'.'||trim(memname)||'(where=(&variable.&op.&value));
title "$1 - ALL DATA FOR '||trim(libname)||'.'||trim(memname)||'";run;');
run;
END
# Run the SAS code
sas -log "$HOME" -sysin "$HOME/printallc.sas"
# Delete the temporary SAS code and optionally the log
rm -f $HOME/printallc.sas # $HOME/printallc.log
# If output file exists then cat it and delete it
if [ -f $HOME/printallc.tmp ]
then
cat $HOME/printallc.tmp
rm -f $HOME/printallc.tmp
fi
E-mail the macro and web site author.