#!/bin/bash
#<pre><b>
# Script     : clash
# Version    : 2.0
# Author     : Roland Rashleigh-Berry
# Date       : 11-Feb-2007
# Purpose    : To identify mismatches in variable properties between datasets
#              (uses SAS).
# SubScripts : clash_win
# Notes      : Make the data directory the current directory
# Usage      : clash
#
#================================================================================
# PARAMETERS:
#-pos- -------------------------------description--------------------------------
# N/A  (none)
#================================================================================
# AMENDMENT HISTORY:
# init --date-- mod-id ----------------------description-------------------------
# rrb  11Feb07         Call clash_win for Windows configurations
#================================================================================
# 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 a Windows config then call clash_win and exit on return
if [ -n "$CYGWIN" ] ; then
  clash_win
  exit $?
fi

sas -stdio -noautoexec -sasuser work 2>/dev/null << -----FINISH-----
options validvarname=any nofmterr;

libname here './' access=readonly;

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 stdout;
  set clash;
  put @1 memname @12 name @24 length @28 type type. @30 newfmt @43 label;
run;
-----FINISH-----
