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

Hi everyone,
when an uninitialized variable is present in a running code, in addition to the note that appears in the log (e.g. NOTE: Variable varXXX is uninitialized.), I would like an alert message to also be printed on the results page.

Has anyone tried this before and knows if there is a way to do it?
Thanks a lot,
Daniele (Italy)

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

It's possible, but it's a good bit of work.

 

Generally with SAS the rule I learned was "you can't trust your results until you check your log."  There are lots of Errors/Warnings/Notes that can appear in the log that should cause you to ignore your results.  So typically big picture, you want to think about easy ways to check your SAS log after a submission.  You can do this, for example, with automated log scanners provided by SAS (Enterprise Guide has some built-in log scanning features), and you can also write your own log scanner, which allows you to configure which Errors/warnings/notes should be caught.

 

My take on this uninitialized note is that it should be an error, not a note.  And happily, SAS added a system option, varinitchk, that allows you to make it an error:

 

1    options varinitchk=error ;
2
3    data want ;
4      set sashelp.class ;
5      Age2=Ag**2 ;
6    run ;

ERROR: Variable Ag is uninitialized.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.WANT may be incomplete.  When this step was stopped there were 0 observations and 7 variables.
WARNING: Data set WORK.WANT was not replaced because this step was stopped.

I would set varinitchk=error by default.  It's a nice example of offensive programming, meaning writing code that is designed to generate loud errors when it encounters problems, rather than quietly handle the errors and keep processing as if nothing is wrong.  I wrote a paper about offensive programming with more thoughts:  https://www.lexjansen.com/sesug/2022/SESUG2022_Paper_187_Final_PDF.pdf

 

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

 

First, find variables that have only missing values. Then once the variables are identified, you will have to write a message to the output yourself.

 

 

This approach will let you find those variables: https://communities.sas.com/t5/SAS-Procedures/Getting-rid-of-all-variables-for-which-there-are-ONLY-...

--
Paige Miller
Quentin
Super User

It's possible, but it's a good bit of work.

 

Generally with SAS the rule I learned was "you can't trust your results until you check your log."  There are lots of Errors/Warnings/Notes that can appear in the log that should cause you to ignore your results.  So typically big picture, you want to think about easy ways to check your SAS log after a submission.  You can do this, for example, with automated log scanners provided by SAS (Enterprise Guide has some built-in log scanning features), and you can also write your own log scanner, which allows you to configure which Errors/warnings/notes should be caught.

 

My take on this uninitialized note is that it should be an error, not a note.  And happily, SAS added a system option, varinitchk, that allows you to make it an error:

 

1    options varinitchk=error ;
2
3    data want ;
4      set sashelp.class ;
5      Age2=Ag**2 ;
6    run ;

ERROR: Variable Ag is uninitialized.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.WANT may be incomplete.  When this step was stopped there were 0 observations and 7 variables.
WARNING: Data set WORK.WANT was not replaced because this step was stopped.

I would set varinitchk=error by default.  It's a nice example of offensive programming, meaning writing code that is designed to generate loud errors when it encounters problems, rather than quietly handle the errors and keep processing as if nothing is wrong.  I wrote a paper about offensive programming with more thoughts:  https://www.lexjansen.com/sesug/2022/SESUG2022_Paper_187_Final_PDF.pdf

 

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 361 views
  • 2 likes
  • 3 in conversation