clash

[last updated - 31 July 2003]

After you have built your library of datasets it might be useful to compare identically-named variables to see if there are any differences in variable length, format, labels etc. This is what this utility does. You make the data directory the current directory and type in clash in the terminal window. As always, output goes to the terminal window by default and it is up to you to redirect it if required.


#!/bin/sh
# Script     : clash
# Version    : 1.0
# Author     : Roland Rashleigh-Berry
# Date       : 31 July 2003
# Contact    : roland@rashleigh-berry.fsnet.co.uk
# Purpose    : To identify mismatches in variables between datasets 
# SubScripts : none
# Notes      : Make the data directory the current directory
# Usage      : clash
# 
#================================================================================
# PARAMETERS:
#-pos- -------------------------------description--------------------------------
# N/A  (none)
#================================================================================
# AMENDMENT HISTORY:
# init --date-- mod-id ----------------------description-------------------------
# 
#================================================================================


# check on the existence of a sas program in the home directory
if [ -f $HOME/clash.sas ] ; then
  echo "SAS program clash already exists in your home directory. You need to check" 1>&2
  echo "if you need it and delete it if not. This utility will not overwrite it and" 1>&2
  echo "will now exit." 1>&2
  exit 1
fi

# Write SAS code out to a temporary file
cat > $HOME/clash.sas << END
options validvarname=any nofmterr;

libname here './' access=readonly;

filename _outfile "$HOME/clash.tmp";

proc format;
  value type 1='N' 2='C';
run;

proc contents noprint data=here._all_ out=contents;
run;

data contents;
  length newfmt $ 15;
  set contents; 
  newfmt=format;
  if formatl>0 then do;
    newfmt=trim(newfmt)||compress(put(formatl,3.))||'.';
    if formatd>0 then newfmt=trim(newfmt)||compress(put(formatd,3.));
  end;
  else if newfmt ne ' ' then newfmt=trim(newfmt)||'.';
run;

proc sort data=contents;
  by name;
run;

proc sort nodupkey data=contents(keep=name length type newfmt label)
                    out=clash;
  by name length type newfmt label;
run;

data clash(keep=name);
  set clash;
  by name;
  if first.name and not last.name then output;
run;

data clash;
  merge clash(in=_clash) contents;
  by name;
  if _clash;
run;

data _null_;
  file _outfile;
  set clash;
  put @1 memname @10 name @22 length @26 type type. @28 newfmt @41 label;
run;
END


# Run the SAS code
sas -log "$HOME" -sysin "$HOME/clash.sas"


# Delete the temporary SAS code and optionally the log
rm -f $HOME/clash.sas # $HOME/clash.log 


# If output file exists then cat it and delete it
if [ -f $HOME/clash.tmp ]
then
  cat $HOME/clash.tmp
  rm -f $HOME/clash.tmp
fi

Go back to the home page.

E-mail the macro and web site author.