Desktop productivity for business analysts and programmers

Reading 3 different server directory at same time

Super Contributor
Super Contributor
Posts: 318

Reading 3 different server directory at same time


I am using SAS EG 5.1. where 3 different server defined (server1 to server3). under each defined server i have log files under specific dir path.

server1 (dir path=w:\woo\market_log)      - have 10 log files

server2 (dir path=w:\woo\business_log)        - have 5 log fiels

server2 (dir path=w:\woo\finance_log)       - have 15 log fiels

can i use below code (online code to check for errors and warning and other info) to grab all 3 dir path logs from 3 different server at once OR i must have to run below code 3 times one by one by selecting each and every server (server1 to server3) ?

********online code***************;

%macro scanlog (path=);

options nodate nonumber noxwait;

%let path=%sysfunc(tranwrd(&path,/,\));

** Delete the previous version **;

x(del &path\files.txt);

** Output the list of files to a temporary location **;

x(dir /b &path\*.log >> &path\files.txt);

** Initialize the macro variables **;

%let totfile=;

%let totobs=;

** Get the total number of files and file names **;

data _null_;

infile "&path\files.txt" dsd dlm='09'x truncover;

input name $40.;

call symput('totfile',trim(left(put(_n_,8.))));

call symput('file'||trim(left(put(_n_,8.))),trim(left(name)));


%do i=1 %to &totfile;

data files;

infile "&path\&&file&i" dsd dlm='09'x truncover;

input line $200.;

length filenm $40.;


if index(line,'fatal') then cnt1+1;

if substr(line,1,5)='ERROR' then cnt2+1;

if substr(line,1,7)='WARNING' then cnt3+1;

if index(line,'uninitialized') then cnt4+1;

if index(line,'MERGE statement has more than') then cnt5+1;

if index(line,'values have been converted') then cnt6+1;

if index(line,'Note: Missing') then cnt7+1;

if index(line,'Note: Invalid argument') then cnt8+1;

if index(line,'W.D format was too small') then cnt9+1;

if index(line,'has 0 observations') then cnt10+1;

if index(line,'variables not in') then cnt11+1;

if index(line,'variables have conflicting') then cnt12+1;

if index(line,'unequal') then cnt13+1;

if index(line,'Division by zero detected') then cnt14+1;

if index(line,'operations could not be performed') then cnt15+1;

if index(line,'duplicate key values were deleted') then cnt16+1;


proc univariate data=files noprint;

by filenm;

var cnt1-cnt16;

output out=stat1 max=max1-max16;


proc transpose data=stat1 out=stat2(where=(col1>0));

by filenm;

var max1-max16;


data final;

set %if &i>1 %then %do; final %end; stat2;

%if &i=&totfile %then %do;

length desc $100.;

if lowcase(_name_)='max1' then desc='fatal';

if lowcase(_name_)='max2' then desc='ERROR';

if lowcase(_name_)='max3' then desc='WARNING:';

if lowcase(_name_)='max4' then desc='uninitialized';

if lowcase(_name_)='max5' then

desc='Merge statement has more than one data set with repeats

of BY values';

if lowcase(_name_)='max6' then

desc='values have been converted';

if lowcase(_name_)='max7' then desc='Note: Missing';

if lowcase(_name_)='max8' then desc='Note: Invalid argument';

if lowcase(_name_)='max9' then desc='W.D format was too small';

if lowcase(_name_)='max10' then desc='has 0 observations';

if lowcase(_name_)='max11' then desc='variables not in';

if lowcase(_name_)='max12' then

desc='variables have conflicting attributes';

if lowcase(_name_)='max13' then desc='unequal';

if lowcase(_name_)='max14' then

desc='Division by zero detected';

if lowcase(_name_)='max15' then

desc='Mathematical operation could not be performed';

if lowcase(_name_)='max16' then

desc='observations with duplicate key values were deleted';

drop _name_ _label_;




** Get the total number of occurrences of unwanted messages **;

data _null_;

set final nobs=last;

if last then call symput('totobs',trim(left(put(_n_,8.))));


** Final output **;

ods listing close;

ods noresults;

ods html file="&path\scanlog.html";

title1 "Summary of Log Files";

title2 "&path folder";

%if &totobs=0 %then %do;

data _null_;

file print;

put "============================";


put "*** NO BAD GUYS!!! FOUND ***";

put "============================";



%else %do;

proc report data=final headline headskip split='|' missing nowd;

columns filenm col1 desc;

define filenm / order order=data


style(header)=[just=left] 'File';

define col1 / style(column)=[cellwidth=1in]

center 'n' format=3.;

define desc / style(column)=[cellwidth=5.5in]

style(header)=[just=left] 'Description';

compute before filenm;

line ' ';




%mend scanlog;


Valued Guide
Posts: 3,206

Re: Reading 3 different server directory at same time

Use the filevar option with the input statement SAS(R) 9.3 Statements: Reference

---->-- ja karman --<-----
Esteemed Advisor
Posts: 6,706

Re: Reading 3 different server directory at same time

This depends on your storage setup.

If w:\ is a shared network drive and all the subdirs are visible to a single client (one of your workspace servers), then you can run the logcheck from there.

If w: is actually local to each server, or policies prevent (eg) server1 from accessing business_log or finance_log, then you need to run the jobs separately.

Maxims of Maximally Efficient SAS Programmers
Super Contributor
Super Contributor
Posts: 318

Re: Reading 3 different server directory at same time

thank you Jaap and Kurt...

Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation