Create errors when variables are uninitialized

Accepted Solution Solved
Reply
Contributor
Posts: 32
Accepted Solution

Create errors when variables are uninitialized

Hey community,

I would like to know if there is a possibility to create an ERROR instead of a simple NOTE, when SAS comes across an unitialized variable (in a data step).

Thanks in advance.

Regards,

Andreas


Accepted Solutions
Solution
‎06-23-2015 05:51 AM
Respected Advisor
Posts: 3,890

Re: Create errors when variables are uninitialized

Beginning with SAS9.4 there is a new option "VARINITCHK" which would give you what you're after.  SAS(R) 9.4 System Options: Reference, Third Edition

View solution in original post


All Replies
Super User
Super User
Posts: 7,401

Re: Create errors when variables are uninitialized

I wouldn't think so as its not an error (just bad programming practice).  SAS can hold empty variables so its just informing you that it was not used.  Personally, I would say fix the coding, there's no reason why there would need to be these in the log in the first place, even if you do want a blank variable then: var=""; would suffice, then it is clear that it is meant.

You could post process a dataset to see what new variables are created (keep SASHELP.VCOLUMN, and then again after run, merge the two where not in both to get list of new variables) then check if any contain no data.  But why, seems to be fixing a problem which shouldn't be there in the first place.

Contributor
Posts: 32

Re: Create errors when variables are uninitialized

You are right: these notes shouldn't be in the log at all.

The problem is that my SAS process is getting more and more complicated. I sometimes had the problem that I had a typo in a variable name and SAS started calculating with missing values. Or I deleted a variable in a data set where this variable was later used but I wasn't aware of it in the first place. Additionally we are several colleagues working on different parts of the SAS process.

The reason why I (and also my colleagues) would like to have these notes of unitialized variables as an error or a warning is that we would notice it earlier and do not lose so much time by looking for the problem.

Super User
Super User
Posts: 7,401

Re: Create errors when variables are uninitialized

If its a complicated process with multiple team members, then you would be best of following Software Development Lifecycle processes.  Define the problem, scope certain areas for certain people, break the problem down, document and detail each section etc.  Then the coding should be next to nothing.  The problem sounds like it arises when programmers (and we are all guilty) just charge ahead bashing out lines of code without a spec or plan. 

If its really a problem, then in your detailed plan define something along the lines of Interfaces, i.e. this part of the code will have datasets a, b and c which contains these variables.  You can then add code in at these interface sections which check the datasets for conformity.  A bit like having data transfer documentation that detail structure (and possibly content).

Solution
‎06-23-2015 05:51 AM
Respected Advisor
Posts: 3,890

Re: Create errors when variables are uninitialized

Beginning with SAS9.4 there is a new option "VARINITCHK" which would give you what you're after.  SAS(R) 9.4 System Options: Reference, Third Edition

Contributor
Posts: 32

Re: Create errors when variables are uninitialized

Great info. Thanks a lot, Patrick!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 252 views
  • 3 likes
  • 3 in conversation