BookmarkSubscribeRSS Feed
ravi15
Calcite | Level 5

/**************************************************************************************/
/* Program: PARSE_RTRACE_LOGS.sas */
/* */
/* Purpose: This program retrieves the file attributes owner, modified */
/* along with the creation timestamp and process id from the */
/* filename. */
/**************************************************************************************/
options msglevel=i;
/* location for historical dataset */
libname in1 "/SASHome/user";
/* location where rtrace logs are stored */
%let subdir=/SASHome/rtrace/Logs/;
data work.dirlist(keep=filename strUser ModDT CrDT strPID strSource);
/* must be explicitly set to blank to have the filename function generate a fileref */
fileref = ' ';
rc = filename(fileref,"&subdir");
/* open fileref and loop throughfilenames */
did=dopen(fileref);
do i = 1 to dnum(did);
/* extract filename */
fileName = dread(did,i);
/* find the position of PID in the filename */
pid_start = index(fileName,"PID")+3;
/* find the end position of PIF in filename */
pid_end = index(fileName,"DATE")-1;
/* extract PID */
strPID = substr(fileName,pid_start,pid_end - pid_start);
/* find the start of DATE in filename */
date_start = index(fileName,"DATE")+4;
/* find the end position of DATE in the filename */
date_end = index(fileName,":")-1;
/* set the start of the time field */
time_start = date_end +2;
/* find the end of the time field */
time_end = index(filename,".");
/* extract creation time */
tmpTime = Trim(substr(filename, time_start, time_end - time_start));
tmpHour = Substr(tmpTime,1, 2)*1;
tmpMin = Substr(tmpTime,3,2)*1;
tmpSec = Substr(tmpTime,5,2)*1;
/* extract creation date */
strDT = trim(substr(fileName,date_start,date_end - (date_start-1)));
tmpDT = input(put(strDT,8.),yymmdd8.);
CrDt = DHMS(put(tmpDT,8.),tmpHour,tmpMin,tmpSec);
fid = mopen(did,fileName);
infonum=foptnum(fid);
if fid then do;
/* extract userid */
strUser=finfo(fid, foptname(fid, 2));
/* extract file modified date */
ModDT=input(trim(finfo(fid, foptname(fid, 5))),datetime20.);
format ModDT CrDT datetime20.;
/* extract file location */
strSource = finfo(fid, foptname(fid, 1));
output;
end;
end;
rc = dclose(did);
rc = filename(fileref);
run;

 

 

When i run  this i am getting the ERROR about the Do loop as below

 

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
65:11 66:10 67:10 71:13
INFO: Character variables have defaulted to a length of 200 at the places given by: (Line):(Column). Truncation can result.
48:1 fileName
76:1 strUser
81:1 strSource
NOTE: Argument 1 to function DNUM(0) at line 46 column 14 is invalid.
ERROR: Invalid DO loop control information, either the INITIAL or TO expression is missing or the BY expression is missing, zero,
or invalid.
fileref=# rc=0 did=0 i=1 fileName= pid_start=. pid_end=. strPID= date_start=. date_end=. time_start=. time_end=. tmpTime=
tmpHour=. tmpMin=. tmpSec=. strDT= tmpDT=. CrDt=. fid=. infonum=. strUser= ModDT=. strSource= _ERROR_=1 _N_=1
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to
missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 46:14
NOTE: The SAS System stopped processing this step because of errors.

 

Any help regarding this is much appreciated.

 

Thank you,

Ravi.

5 REPLIES 5
Astounding
PROC Star

Some places to investigate ...

 

DNUM(0) means that DOPEN failed to find the file you are looking for.  Perhaps it doesn't exist or ...

 

Perhaps fileref=' ' defines FILEREF as a single character.  Perhaps the values you need to assign are longer than that.

ravi15
Calcite | Level 5

Issue solved. I've ginen longer charecter in fileref filesref='                 ';

 

Thank you verymuch for your help.

 

SriLaxman
Fluorite | Level 6

Hello, Can you tell me how many characters you gave?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

Wel, its pretty difficult to debug all that code without all the other information.  So what I will point out to you is:

NOTE: Argument 1 to function DNUM(0) at line 46 column 14 is invalid.

 

This relates to the code:

rc = filename(fileref,"&subdir");
/* open fileref and loop throughfilenames */
did=dopen(fileref);
do i = 1 to dnum(did);

 

It is sayin that did resolves to 0 - maybe fileref is not assigned, what is &subdir. resolving to, is is a valid path, do you have access etc.  At no point in that code is there a specification of &subdir. and even if there was I can't see your system to answer this.  You will need to debug this - see what &subdir resolves to then check that against what you have access to and make sure there is something in that folder.

ravi15
Calcite | Level 5

Thank you very much for you help. I've to give longer space in the fileref 

 

Fileref= '                 '; 

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 8212 views
  • 0 likes
  • 4 in conversation