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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 1 reply
  • 879 views
  • 0 likes
  • 2 in conversation