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)
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
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-...
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
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.