hdr

[last updated - 29 July 2003]

This is where you use your script skills and especially those you learned in this tutorial to amend this script to give you a standard SAS program header with all the details filled in where possible. As always, I introduce new things in each script. In it you will see what is called a "here document". You use cat to write lines out to a file and you tell it the terminating characters to expect at the end. If you look at the code below you will see this.

Don't expect this to work. You are going to have to get this to work yourself. I don't know what your standard header is supposed to look like and I don't know where to find your protocol and study information if you need to include that in your standard SAS program header. The rest is up to you. You are a shell script programmer now.

#!/bin/sh
# Script     : hdr
# Version    : 1.0
# Author     : Roland Rashleigh-Berry
# Date       : 29 July 2003
# Contact    : roland@rashleigh-berry.fsnet.co.uk
# Purpose    : To create a standard SAS program header
# SubScripts : getname
# Notes      : This shell script generates a SAS program header but this script
#              will need extensive amendments to make it generate the correct
#              standard header for your site and will also need extensive
#              amendments to pick up the correct protocol and study from your
#              directory path or wherever it is supposed to come from.
# Usage      : hdr
#              hdr progname
#================================================================================
# PARAMETERS:
#-pos- -------------------------------description--------------------------------
#  1   program name (optional)
#================================================================================
# AMENDMENT HISTORY:
# init --date-- mod-id ----------------------description-------------------------
# 
#================================================================================
# This is public domain software. No guarantee as to suitability or accuracy is
# given or implied. User uses this code entirely at their own risk.
#================================================================================

if [ $# -lt 1 ]
then
  echo -n "Enter program name: "
  read progname
else
  progname=$1
fi

progname=`echo $progname | awk -F. '{print $1 ".sas"}'`

echo -n "Enter program purpose: "
read purpose

author=`getname`

date=`date '+%d-%b-%Y'`

prot=`pwd | sed "s%^$RD%%" | awk -F/ '{print $1}'`
study=`pwd | sed "s%^$RD%%" | awk -F/ '{print $2}'`


cat > $HOME/sashdr.tmp << FINISH
/*
/ Program   : $progname
/ Version   : 1.0
/ Author    : $author
/ Date      : $date
/ prot/study: $prot / $study
/ Purpose   : $purpose
/ Notes     : 
/ Usage     : 
/ 
/================================================================================
/ AMENDMENT HISTORY:
/ init --date-- mod-id ----------------------description-------------------------
/ 
/===============================================================================*/

FINISH

if [ -f $progname ]
then
  cat $HOME/sashdr.tmp $progname > $HOME/sashdr2.tmp
  rm -f $progname
  cat $HOME/sashdr2.tmp > $progname
  rm -f $HOME/sashdr2.tmp
else
  cat $HOME/sashdr.tmp > $progname
  echo "created $progname"
fi

rm -f $HOME/sashdr.tmp

Go back to the home page.

E-mail the macro and web site author.