#!/bin/bash
#<pre><b>
# Script     : intitlesds
# Version    : 2.1
# Author     : Roland Rashleigh-Berry
# Date       : 02-Mar-2007
# Purpose    : Production script to list all the programs in the titles dataset
#              (uses SAS).
# SubScripts : intitlesds_win
# SubMacros  : %allocr
# Notes      : The case will be the same as that held in the titles dataset.
#              You must add the .sas extension to the list yourself if needed.
#              The list is written to standard output. Duplicate program names
#              are dropped.
# Usage      : intitlesds
#
#===============================================================================
# PARAMETERS:
#-pos- -------------------------------description-------------------------------
# N/A  Do not supply any parameters
#===============================================================================
# AMENDMENT HISTORY:
# init --date-- mod-id ----------------------description------------------------
# rrb  24Nov05         -stdio used for sas invocation
# rrb  11Feb07         Call intitlesds_win for Windows configurations
# rrb  20Feb07         Call %allocr macro
# rrb  02Mar07         Use "&_ptlibref_.." instead of "der."
#===============================================================================
# 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.
#===============================================================================

# No parameters required
if [ $# -gt 0 ] ; then
  echo "Error: (intitlesds) Do not supply any parameters" 1>&2
  exit 2
fi

# if a Windows config then call intitlesds_win and exit on return
if [ -n "$CYGWIN" ] ; then
  intitlesds_win
  exit $?
fi

# Feed SAS code into standard input
sas -stdio -sasuser work 2>/dev/null << -----FINISH-----
%allocr
options validvarname=v7 nofmterr noovp nodate nonumber;
proc sort nodupkey data=&_ptlibref_..titles(where=(type='T' and number=1))
                    out=_titles(keep=program);
  by program;
run;
data _null_;
  file stdout;
  set _titles;
  put @1 program;
run;
-----FINISH-----
