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 (.)
case
when t1.A = '.' then sum(t1.B)
when t1.B = '.' then sum(t1.A)
else sum(t1.A, t1.B)
end
However how I do I go about checking for non-existing columns.
Thanks,
Dhanashree
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?
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,
Tom
Thanks, I guess the solution to using column names from dictionary will be useful as well.
Appreciate the guideline RW9
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.