#!/usr/bin/sh ################################################################################### # Script name: pc # # Show SAS proc contents output # # example: # > pc adsl ################################################################################### # Base name of this script typeset basename=${0##*/} # Check if there are too many parameters if [[ $# -gt 3 ]];then print "Too many paramters, please refer to usage by typing pc at the prompt..." exit 5 fi # Usage description function usage { clear cat << END_OF_HELP pc {proc contents} SYNTAX: pc dataset -linesize DESCRIPTION: Display proc contents output. Variables are displayed in alphabetical order. Use '| sort -n' to display variables in order as in dataset. OPTIONS: -linesize -- Optional. Allows you to specify the linesize of the SAS output. Default is 80. -h -- Displays help text. USAGE: If current directory is /prog then search for the first occurence of the specified SAS dataset in the following order: 1. anadata 2. sdtmdata 4. rawdata If current directory is not /prog then only search current directory. 1. current directory You can use this tool on only one SAS dataset at a time. EXAMPLE: #1: pc adsl #2: pc adsl -140 #3: pc adsl | sort -n (sort by variable order in dataset) exiting... END_OF_HELP } # If no dataset is specified, show usage if [ "$1" = "" ] || [ "$1" = "-h" ]; then usage exit 4 fi # Defaults the linesize of the SAS output to 80, or set to some other value if there are user inputs if echo "$1" | grep -q -E '^-[0-9]+$'; then print "Please use the linesize option only after dataset name..." exit 3 elif echo "$2" | grep -q -E '^-[0-9]+$'; then typeset linesize=`echo $2 | sed "s/-//g"` set $1 "" else typeset linesize=80 fi # Create unique and temporary log and sas program names tempname=$(mktemp) sasfile=$tempname.sas log=$tempname.log ofile=$tempname.out # The first parameter is the file path typeset filepath=`echo $1 | sed "s/.ssd01//;s/.sas7bdat//;s/.*\.//"` typeset library=$(dirname $filepath) typeset dataset=$(basename $filepath) # Save the present working directory typeset pwd=$(pwd) typeset up1=$(dirname $pwd) typeset cdir=$(basename $pwd) # Search for the SAS dataset # If current directory is not /prog then only search in current directory # else search in all anadata, sdtmdata, odsdata and rawdata if [[ "$cdir" != "prog" ]]; then if [ -f $filepath.sas7bdat ]; then typeset sasdir="$pwd" typeset dsndir=pwd else echo "Dataset: $pwd/$dataset.sas7bdat not found." echo "Exiting . . ." exit 1 fi else if [ -f ../anadata/$dataset.sas7bdat ]; then typeset sasdir="$up1/anadata" typeset dsndir=anadata elif [ -f ../sdtmdata/$dataset.sas7bdat ]; then typeset sasdir="$up1/sdtmdata" typeset dsndir=sdtmdata elif [ -f ../rawdata/$dataset.sas7bdat ]; then typeset sasdir="$up1/rawdata" typeset dsndir=rawdata else echo "Dataset: $dataset.sas7bdat not found. Exiting . . . " exit 1 fi fi echo "Running proc contents on dataset: $dataset ($sasdir)" # Begin constructing the sas program cat >> $sasfile << SAS_TEXT libname $dsndir '$sasdir' access=readonly; options nocenter nofmterr pagesize=max linesize=$linesize nonumber nodate; title;footnote; proc contents data=$dsndir.$dataset; run; SAS_TEXT sas -nodms -noautoexec -stdio $sasfile 2>$log | more -40 grep -F -e 'ERROR' -e 'WARNING' <$log #more $log rm -f $sasfile $log rm -f $tempname