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

Hi Guys,

I am new to SAS programming. Just wondering if there is a Python for each loop equivalent in SAS.

 

I have a log file in text file format  in below pattern

 

NOTE: Table table_name1 created with 100 rows and 101 columns.

real time 0.14 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 343.43k
OS Memory 8412.00k
Timestamp 08/30/2018 07:40:29 AM

NOTE: Table table_name2 created, with 473 rows and 80 columns.
real time 9.70 seconds
user cpu time 2.05 seconds
system cpu time 1.43 seconds
memory 270071.73k
OS Memory 279412.00k
Timestamp 08/31/2018 07:40:32 AM

 

So using Datastep 

how do i loop through each row and check for only the rows which starts with string "NOTE: Table" and keep only the table name and remove all other strings.

 

 

Thanks in Advance

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @sreevatsan1991 and welcome to the SAS Support Communities!

 

 

 

Try this:

data _null_;
infile 'path_to_your_logfile';
file 'path_to_text_file_to_be_created';
input;
if _infile_=:'NOTE: Table' then _infile_=scan(substr(_infile_,13),1);
put _infile_;
run;

It's possible to edit the log file in place, but I'd prefer the approach suggested above, i.e. creating a new text file containing the modified log.

 

 

View solution in original post

5 REPLIES 5
mdavidson
Quartz | Level 8

Give this a try, also be aware of the upper and lower case in your log.

 

data logscan;
infile  "C:\your log file goes here\.log" truncover;
input a_line $200.;
if index(a_line, 'ERROR:') > 0 or
index(a_line, 'WARNING') > 0 or
index(a_line, 'NOTE')
then output;
run;
sreevatsan1991
Obsidian | Level 7

Hey there. Thanks a lot for your response. Sorry for my lack of clarity.

I don't want  to extract only the line 

"NOTE: Table table_name1 created with 100 rows and 101 columns."

I want to replace the above line keeping only the table name.

So my output should look like below:

 

table_name1

real time 0.14 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 343.43k
OS Memory 8412.00k
Timestamp 08/30/2018 07:40:29 AM

table_name2
real time 9.70 seconds
user cpu time 2.05 seconds
system cpu time 1.43 seconds
memory 270071.73k
OS Memory 279412.00k
Timestamp 08/31/2018 07:40:32 AM

 

Thanks again for your response!

FreelanceReinh
Jade | Level 19

Hi @sreevatsan1991 and welcome to the SAS Support Communities!

 

 

 

Try this:

data _null_;
infile 'path_to_your_logfile';
file 'path_to_text_file_to_be_created';
input;
if _infile_=:'NOTE: Table' then _infile_=scan(substr(_infile_,13),1);
put _infile_;
run;

It's possible to edit the log file in place, but I'd prefer the approach suggested above, i.e. creating a new text file containing the modified log.

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 2969 views
  • 2 likes
  • 4 in conversation