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
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.
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;
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!
If youre parsing a log I recommend PROC SCAPROC.
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.
Thanks a lot Richard. This did the trick ![]()
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.