LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (November 2005, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 30 Nov 2005 00:18:27 -0800
Reply-To:     RolandRB <rolandberry@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         RolandRB <rolandberry@HOTMAIL.COM>
Organization: http://groups.google.com
Subject:      A SAS utility shell script
Comments: To: sas-l@uga.edu
Content-Type: text/plain; charset="iso-8859-1"

After spending two years in the dark not knowing the best way to run sas from a shell script and route output to standard output without having a code member and log kicking around if the utility gets interrupted, I finally discovered it. You can put SAS code in a "here document" and route the log to /dev/null where it will get swallowed up. Here is a very simple script that will do a proc summary in the current directory and print the results to standard output.

#!/bin/bash # Script : summary # Version : 1.0 # Author : Roland Rashleigh-Berry # Date : 23-Aug-2004 # Purpose : To run "proc summary" on a dataset and display the output data set # (uses SAS). # SubScripts : none # Notes : SAS dataset file name extension .sas7bdat will be ignored. You # can subset the output dataset. See usage notes. # Usage : summary sex acct # summary 'sex agesub' acct # summary 'sex agesub' 'acct(where=(fascd=1))' # summary 'sex agesub' 'acct(where=(fascd=1))' 'where _freq_>20' #================================================================================ # PARAMETERS: #-pos- -------------------------------description-------------------------------- # 1 Variable(s) to summarise. If more than one then enclose in single quotes # and separate with spaces. See usage notes. # 2 Input dataset. Too add a "where" clause put in quotes. See usage notes. # 3 Subset clause on output dataset if required. See usage notes. #================================================================================ # AMENDMENT HISTORY: # init --date-- mod-id ----------------------description------------------------- # #================================================================================

# Put out a usage message if not enough parameters supplied if [ $# -lt 2 ] ; then echo "Usage: summary 'var1 var2' dataset 'where _freq_ GT 1'" 1>&2 exit 1 fi

dset=$(echo $2 | sed 's%\.sas7bdat$%%')

# Feed SAS code into standard input sas -stdio -noautoexec -sasuser work 2>/dev/null << ----END---- options validvarname=any nofmterr nocenter nodate nonumber; libname here './' access=readonly; proc summary nway missing data=here.$dset; class $1; output out=summary(drop=_type_); run; title; proc print data=summary; $3; run; ----END----


Back to: Top of message | Previous page | Main SAS-L page