REM ################################################################################### REM # Script name: pc REM # REM # Show SAS proc contents output REM # REM # example: REM # > pc adsl REM ################################################################################### @echo off setlocal REM Check if there are too many parameters set argC=0 for %%x in (%*) do Set /A argC+=1 if %argC% geq 4 ( echo Too many paramters, please refer to usage by typing pc at the prompt . . . GOTO USAGE ) REM If no dataset is specified, show usage set err1=false if "%1" == "" set err1=true if "%1" == "-h" set err1=true if "%err1%"=="true" ( GOTO USAGE ) else ( REM Create unique and temporary log and sas program names set tempname=%tmp%\pc-%random% set sasfile=%tempname%.sas set logfile=%tempname%.log set lstfile=%tempname%.lst set dataset=%1 REM Save the present working directory set pwd=. for %%d in (".") do set cdir=%%~nxd ) REM Defaults the linesize of the SAS output to 80, or set to some other value if there are user inputs REM setlocal EnableDelayedExpansion if /i "%dataset:~0,1%"=="-" ( echo Please use the linesize option only after dataset name . . . GOTO USAGE ) set arg2=%2 if /i "%arg2:~0,1%"=="-" ( set "var="&for /f "delims=-0123456789" %%i in ("%2") do set var=%%i if defined var ( echo Linesize %2 NOT numeric. Default linesize=80 will be used. set linesize=80 ) else ( set linesize=%arg2:~1% ) ) else ( set linesize=80 ) REM If -n sort flag is set set sortfl=false if "%2" == "-n" set sortfl=true if "%3" == "-n" set sortfl=true if "%sortfl%"=="true" ( set sortopt=order=varnum ) REM Search for the SAS dataset REM If current directory is not /prog then only search in current directory REM else search in all anadata, sdtmdata, odsdata and rawdata set dsndir= set sasdir= if not "%cdir%" == "prog" ( if exist "%dataset%.sas7bdat" ( set sasdir=. set dsndir=cwd ) else ( echo "Dataset: ./%dataset%.sas7bdat not found." echo "Exiting . . ." ) ) else ( if exist "..\anadata\%dataset%.sas7bdat" ( set sasdir="..\anadata" set dsndir=anadata ) if exist "..\sdtmdata\%dataset%.sas7bdat" ( set sasdir="..\sdtmdata" set dsndir=sdtmdata ) if exist "..\rawdata\%dataset%.sas7bdat" ( set sasdir="..\rawdata" set dsndir=rawdata ) if NOT defined dsndir ( echo Dataset: %dataset%.sas7bdat not found. Exiting . . . GOTO END ) ) echo Running proc contents on dataset: %dataset% (%sasdir%) REM Begin constructing the sas program echo libname %dsndir% %sasdir% access=readonly; > %sasfile% echo options nocenter nofmterr pagesize=max linesize=%linesize% nonumber nodate; >> %sasfile% echo title;footnote; >> %sasfile% echo proc contents data=%dsndir%.%dataset% %sortopt%; run; >> %sasfile% set sas="C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" %sas% -icon -nosplash -nologo -rsasuser -sysin %sasfile% -log %logfile% -print %lstfile% more %lstfile% REM Clean up del %sasfile% del %logfile% del %lstfile% GOTO END :USAGE REM Usage description REM cls echo. echo pc {proc contents} echo. echo SYNTAX: pc dataset -linesize echo. echo DESCRIPTION: Display proc contents output. Variables are displayed in alphabetical order. echo. echo OPTIONS: echo -linesize -- Optional. echo Allows you to specify the linesize of the SAS output. echo Default is 80. echo. echo -h -- Displays help text. echo. echo USAGE: If current directory is /prog then search for the first occurence of the echo specified SAS dataset in the following order: echo 1. anadata echo 2. sdtmdata echo 3. rawdata echo. echo If current directory is not /prog then only search current directory. echo 1. current directory echo. echo You can use this tool on only one SAS dataset at a time. echo. echo EXAMPLE: echo #1: pc adsl echo #2: pc adsl -140 echo #3: pc adsl -140 -n -> Display the variables as in dataset echo #3: pc adsl -140 /+1 -> Display the variables as in dataset echo. :END