BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
oljasomar
Calcite | Level 5

Hello,

 

I'm new in SAS and need some help.

I wrote code which parses log and stores result in dataset. However, there are multiple logs, and I need them to be passed to the code. 

 

Infile should accept log names dynamically from file_list.

 

filename indata pipe 'dir /sas/sasconfig/Lev1/SASApp/WorkspaceServer/Logs /b';
data file_list;
 length fname $128;
 infile indata truncover; /* infile statement for file names */
 input fname $128.; /* read the file names from the directory */
 call symput ('num_files',_n_); /* store the record number in a macro variable */
run;

 

 

%macro csss;
data x_wo_step(keep= text ds_name ds_count real_time) w_step(keep=ds_name step_used) x_step(keep=ds_name memory) project_name(keep=ds_name proj_name);
infile "/sas/sasconfig/Lev1/SASApp/WorkspaceServer/Logs/SASMain_WorkspaceServer_2019-02-17_08:00_65658_pussurmanov.log" truncover end=eof;
input text $1000. ;
retain ds_name ds_count ;

if findw(text,"NOTE: The data set", ' ', 'E') eq 6 then do;
ds_name = scan(text,10," ");
ds_count = scan(text,12," ");
output x_wo_step;
end;

else if findw(text,"NOTE: Table", ' ', 'E') eq 6 then do;
ds_name = scan(text,8," ");
ds_count = scan(text,11," ");
output x_wo_step;
end;

............

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

You do this in two steps. The first one reads the filenames into a dataset, while the second one uses that dataset to dynamically open the files and read them:

filename indata pipe 'dir /sas/sasconfig/Lev1/SASApp/WorkspaceServer/Logs /b';

data file_list;
 length fname $128;
 infile indata truncover; /* infile statement for file names */
 input fname $128.; /* read the file names from the directory */
run;

data
  x_wo_step (keep=fname text ds_name ds_count real_time)
  w_step (keep=fname ds_name step_used)
  x_step (keep=fname ds_name memory)
  project_name (keep=fname ds_name proj_name)
;
set file_list;
do until (eof);
  infile dummy filevar=fname truncover end=eof;
  input text $1000. ;
  if findw(text,"NOTE: The data set", ' ', 'E') eq 1 then do;
    ds_name = scan(text,5," ");
    ds_count = scan(text,7," ");
    output x_wo_step;
  end;
  else if findw(text,"NOTE: Table", ' ', 'E') eq 1 then do;
    ds_name = scan(text,3," ");
    ds_count = scan(text,6," ");
    output x_wo_step;
  end;
end;
run;

Add code for what you want in w_step, x_step and project_name.

Note that your checks for findw were off (the NOTEs always appear in position 1) and the second arguments for the scan() function calls are different.

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

You do this in two steps. The first one reads the filenames into a dataset, while the second one uses that dataset to dynamically open the files and read them:

filename indata pipe 'dir /sas/sasconfig/Lev1/SASApp/WorkspaceServer/Logs /b';

data file_list;
 length fname $128;
 infile indata truncover; /* infile statement for file names */
 input fname $128.; /* read the file names from the directory */
run;

data
  x_wo_step (keep=fname text ds_name ds_count real_time)
  w_step (keep=fname ds_name step_used)
  x_step (keep=fname ds_name memory)
  project_name (keep=fname ds_name proj_name)
;
set file_list;
do until (eof);
  infile dummy filevar=fname truncover end=eof;
  input text $1000. ;
  if findw(text,"NOTE: The data set", ' ', 'E') eq 1 then do;
    ds_name = scan(text,5," ");
    ds_count = scan(text,7," ");
    output x_wo_step;
  end;
  else if findw(text,"NOTE: Table", ' ', 'E') eq 1 then do;
    ds_name = scan(text,3," ");
    ds_count = scan(text,6," ");
    output x_wo_step;
  end;
end;
run;

Add code for what you want in w_step, x_step and project_name.

Note that your checks for findw were off (the NOTEs always appear in position 1) and the second arguments for the scan() function calls are different.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 532 views
  • 0 likes
  • 2 in conversation