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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 986 views
  • 0 likes
  • 2 in conversation