03-18-2014 02:22 PM
HEllo EG Users,
I am looking for ways to check for non-existing columns in my intermediate datasets. For example, I calculate sum of two columns A and B as Total
sum(t1.A, t1.B) is computed column Total. However in some scenarios, A might not just exist, and it by that I don't mean that the data is missing and saved as . for column titled A.
Are there relevant IF statements in conditional category that can be used to these kind of checks?
In theory, following code would have worked if I had both columns A and B and the data was missing (.)
when t1.A = '.' then sum(t1.B)
when t1.B = '.' then sum(t1.A)
else sum(t1.A, t1.B)
However how I do I go about checking for non-existing columns.
03-18-2014 03:40 PM
Well, the best is to make sure that you always have the columns that you use in your calculations. One way to handle that is to use template (empty) tables, than append your intermediate data to it.
One other way is to use macro coding, where you can conditionally execute regular SAS code (SQL/Data step/PROC steps).
Which is best depends on how big this problem is, is this some kind of production code?
03-18-2014 04:36 PM
I don't exactly understand what you need, but here are a couple of options:
The Data Set Attributes task in EG produces a SAS dataset containing one row for each column in the datasets;
In PROC SQL, you can query the tables in the "dictionary" library to check what columns exist.
Hope this helps,