Download: Wonderful Unix SAS Scripts: SAS Quickies for Dummies

Microsoft Word – Wonderful Unix SAS Scripts – SAS Quickies for Dummies 5.doc 1 Wonderful Unix SAS Scripts: SAS Quickies for Dummies Raoul Bernal, Amgen Inc., Thousand Oaks, CA ABSTRACT Repeated simple SAS jobs can be executed online, and in real-time to avoid having to directly execute SAS command files, producing immediate results directly into any Unix display window. The trick is to simulate SAS using a Unix script, …

CREATING A SIMPLE UNIX SCRIPT A simple Unix script is composed of a simple command executable in the Unix operating system, with optional parameters. An example script would one that lists all files in a current directory, by time: ls -last *.* Instead of typing this command, a simple executable script that contains this line, say, fl (for f ile l ist) can be saved in utilities folder so that typing fl essentially produces the same results as ls -last *.*. . CREATING SIMPLE SAS UNIX SCRIPTS Creating a SAS Unix script would be more complicated than the simplest Unix commands because we need to specify: a) the SAS procedure, b) the dataset to apply the procedure to, and optionally, c) any condition and option to apply to the dataset. Moreover, we need to create a temporary “behind-the-scenes” SAS job to execute in the background after entering the SAS Unix script in the command line. The objective is to create a SAS Unix script, which, when executed with required dataset, parameters and condition, would be equivalent to executing a SAS job using the same SAS procedure. Examples of SAS Unix scripts will be discussed in detail. A. SAS UNIX SCRIPT pp Command syntax: pp dataset condition 2 This script pp (short for p roc p rint), when executed with parameters dataset and condition, would be equivalent to the execution of the following PROC PRINT code in SAS: p roc p rint data= dataset width=min ; where ( condition ) ; run ; As an example, printing the demo.sas7bdat dataset for patient id 190001001 would simply require the following command: pp demo ” cohort = ‘ A1 ‘ ” which yields the following result: The straightforward Unix script for pp would be: #!/bin/csh -f # pp – prints out all or part of a UNIX dataset using PROC PRINT # The first argument is the dataset set dataset=”$1″ # The second argument is for setting condition to subset the data set condition=”$2″ # Find the dataset file set pwd=`pwd` if (-f $dataset.sas7bdat == 1) then set sasdir = “$pwd” else echo “Dataset: $dataset.sas7bdat not found. Exiting … ” exit endif # Begin constructing the SAS program in the temporary directory /tmp echo “%*include ‘init.sas’ ;” >! /tmp/pp$$.sas echo “libname sasdata ‘$sasdir’ ;” >> /tmp/pp$$.sas # Continue constructing the program echo “options nodate nocenter nofmterr pagesize=74 linesize=132 ;” >> /tmp/pp$$.sas echo “proc printto file=’/tmp/pp$$. lis’ ;” >> /tmp/pp$$.sas echo “title Printing dataset: %nrbquote($dataset) Date: &sysdate. Time: &systime.;” >> /tmp/pp$$.sas echo “data $dataset; set sasdata.$dataset ;” >> /tmp/pp$$.sas if (”$2″ != ”) then echo ” where $condition;” >> /tmp/pp$$.sas endif echo “run;” >> /tmp/pp$$.sas echo ” ” >> /tmp/pp$$.sas echo “proc print data=$dataset;” >> /tmp/pp$$.sas echo “run;” >> /tmp/pp$$.sas echo ” ” >> /tmp/pp$$.sas echo “Running proc print on dataset: $dataset ($sasdir)” # Run the program in the temporary directory ./tmp cd /tmp sas -913 pp$$.sas echo ” ” >> /tmp/pp$$.lis grep -i “sas stopped” /tmp/pp$$.log …

Download Wonderful Unix SAS Scripts: SAS Quickies for Dummies.pdf

Download Free:




Similar Content: