Help using Base SAS procedures

How to remove log numbers?

Reply
Frequent Contributor
Posts: 100

How to remove log numbers?

Experts:
Is there a quick way to remove the log line numbers? In the example below, I'm hoping to remove the '483' ...without having to manually do it. Once a while I didn't save the codes but found them in the log files, then have to remove the numbers before I could submit the code again.
Thank you!
the lazy beginner

483 proc print data=work.Ptest;
484 format hired birth date7.;
485 run;
Super Contributor
Super Contributor
Posts: 3,174

Re: How to remove log numbers?

No SAS system options. Suggest using PROC PRINTTO (or CONFIG option ALTLOG= ) to re-direct the SAS-generated log to an external file and then use a SAS DATA step to INPUT and PUT the log contents, though you will also need to address SAS notes, warnings, maybe even errors, as well as possbly page-title info).

You may find that running SAS code from within a SAS macro may provide some limited relief, or at least different behavior, however don't expect the code to have line-breaks where you might normally expect.

Scott Barry
SBBWorks, Inc.
Frequent Contributor
Posts: 100

Re: How to remove log numbers?

Got it. Thank you. Did not know I could have SAS send log to an external file...Also thanks for the second post. It is hard to teach a beginner, isn't it? Don't know what to do if you experts are not here.
Super User
Posts: 19,768

Re: How to remove log numbers?

This will only work for last submitted code.

Run> Recall Last Submit.

HTH,
Reeza
Super Contributor
Super Contributor
Posts: 3,174

Re: How to remove log numbers?

And presumes you are running the SAS code interactively, if not already obvious from the last post-reply.

Scott Barry
SBBWorks, Inc.
Frequent Contributor
Posts: 100

Re: How to remove log numbers?

Good reminder. It helps. Thanks!
Super User
Posts: 3,250

Re: How to remove log numbers?

Here's another trick that can help with LOG files:

Get your log into the SAS editor using FILE/OPEN.

Press the ALT key and at the same time select the top left-hand corner of your log in the column just to the right of your line numbers by clicking with your mouse button. Now drag the mouse down to the bottom right-hand corner of your log. You should now have highlighted your SAS program without the line numbers.

You still have to do some tidying up to get rid of SAS messages but its a whole lot quicker than editing each line. This trick also works in the LOG window.
Frequent Contributor
Posts: 100

Re: How to remove log numbers?

Very interesting and efficient solution. The first several times I tried, all the lines were selected (including line number). But later I pressed down Alt before clicking on the code and moved the mouse downward first then to the right, no line numbers were selected. Thank you!
Valued Guide
Posts: 2,177

Re: How to remove log numbers?

and here is another
let SAS do the work
have a SAS program
1 open/read that log,
2 recognise relevant lines start with a number
3 open an output.sas.txt file
4 strip the log line number out of the log line
5 write what is left of the log line
data _null_ ;
infile 'C:\Applications\UK.Liquidity2\altlogs\461.log' ;
input @ ;
if _infile_ ne ' ' ; * not blank ;
if '0' < substr( _infile_,1,1) <= '9' ; * begins with number ;
num_end = index( _infile_, ' ' ) ; * find blank ;
_infile_ = substr( _infile_, num_end ) ; * take rest of line ;
file 'output.sas.txt' ;
put _infile_ ;
run ;

rough but ready
Frequent Contributor
Posts: 100

Re: How to remove log numbers?

Thank you for sharing the magic! Not only removed the log numbers but also the SAS messages etc. In other words, the output file only keeps the codes I submitted. BTW, thanks for introducing me to the _infile_, and all the comments you added in to help out the beginner.
N/A
Posts: 1

Re: How to remove log numbers?

I stumbled upon this code, but was unable to get it to work.  I am guessing since 2010 the syntax has changed a bit.  In any case here is an update in case anyone needs to do this:

data _null_;
   infile 'C:\FillMeIn\test.log';
   input @;;

   if _infile_ ne ' '; * not blank ;
   if '0' < substr(_infile_,1,1) <= '9'; * begins with number ;
   num_end = index(_infile_, ' '); * find blank ;
   _infile_ = substr(_infile_, num_end); * take rest of line ;

   file 'C:\FillMeIn\test_no_line_numerbers.log';
   put _infile_;
run;

Respected Advisor
Posts: 4,919

Re: How to remove log numbers?

You may also open your log file with a good programing editor like Notepad++, select the section that you want and use the command Delete line numbers or first word.

PG

PG
jjl
N/A
Posts: 1

Re: How to remove log numbers?

I pasted into Excel, using the text import wizard I set the fixed width so it made a column break after the line number, then I simply copied the second column.

Ask a Question
Discussion stats
  • 12 replies
  • 5639 views
  • 6 likes
  • 8 in conversation