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

Hello,

 

1. Concerning the PUTLOG I understand that it is used to write to the LOG but to help identify errors. But how would you use _N_ or _ERROR_?

_N_  counts the number of iteration

_ERROR_  displays 1 for error occurs 

 

2. Concerning the PUT conditional processing. I don't completely understand the purpose of using PUT statement. I have a example below:

 

data work.test;
       set cert.loan01;
            if code='1' then type='variable'; /*#1*/
            else if code='2' then type='fixed';
            else type='unknown';
if type='unknown' then put 'random items in red '; 
run;

 

When the code is runs it will display in the LOG screen "random items in red". But what is the purpose of displaying the multiple lines and providing the number of observations.

 

random items in red

random items in red

random items in red

random items in red

random items in red

random items in red

random items in red

random items in red

random items in red
NOTE: There were 9 observations read from the data set
CERT.LOAN.
NOTE: The data set WORK.LOAN01 has 9 observations and 6
variables.

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  Both PUT and PUTLOG are capable of writing to the SAS log. However PUTLOG will ONLY write to the SAS log. PUT as a statement can also be used to write to an external file. In the program, as shown below the PUT statement is writing to the log and to an external file:

Cynthia_sas_0-1600971617184.png

 

Note that the yellow highlighted statement (PUTLOG) and the cyan highlighted statement (PUT) both write to the SAS log. using NOTE: at the beginning of the text string caused color coding to be implemented in the log.  However, PUT, when used with a FILE statement changes the behavior of where the PUT statement writes. The PUT statement that immediately follows a FILE statement writes to the file specified, in this case, c:\temp\writeclass.txt. There are many different formatting things I could have done but did not do.

 

I have used _N_ and _ERROR_ in PUTLOG statements for debugging. Typically it has happened when I've had a big program (over 500 lines of code) and there was some logic problem that I needed to trace. The place where I used _N_ and _ERROR_ was to dump an entire observation when I encounted an error to see whether there was bad data or whether my program had failed to account for the condition that broke the logic. In the Programming 2 class, we have some examples of using PUTLOG to help you debug a program. If you are studying for certification and using one of the Prep Guides, it may be useful to review the PUTLOG section in Programming 2.

 

  Maybe others will have some examples of when they've used _N_ and _ERROR_ and PUTLOG for debugging.

 

  Cynthia

View solution in original post

1 REPLY 1
Cynthia_sas
SAS Super FREQ

Hi:

  Both PUT and PUTLOG are capable of writing to the SAS log. However PUTLOG will ONLY write to the SAS log. PUT as a statement can also be used to write to an external file. In the program, as shown below the PUT statement is writing to the log and to an external file:

Cynthia_sas_0-1600971617184.png

 

Note that the yellow highlighted statement (PUTLOG) and the cyan highlighted statement (PUT) both write to the SAS log. using NOTE: at the beginning of the text string caused color coding to be implemented in the log.  However, PUT, when used with a FILE statement changes the behavior of where the PUT statement writes. The PUT statement that immediately follows a FILE statement writes to the file specified, in this case, c:\temp\writeclass.txt. There are many different formatting things I could have done but did not do.

 

I have used _N_ and _ERROR_ in PUTLOG statements for debugging. Typically it has happened when I've had a big program (over 500 lines of code) and there was some logic problem that I needed to trace. The place where I used _N_ and _ERROR_ was to dump an entire observation when I encounted an error to see whether there was bad data or whether my program had failed to account for the condition that broke the logic. In the Programming 2 class, we have some examples of using PUTLOG to help you debug a program. If you are studying for certification and using one of the Prep Guides, it may be useful to review the PUTLOG section in Programming 2.

 

  Maybe others will have some examples of when they've used _N_ and _ERROR_ and PUTLOG for debugging.

 

  Cynthia

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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