Desktop productivity for business analysts and programmers

Check for non-existing columns

Posts: 73

Check for non-existing columns

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.



Esteemed Advisor
Posts: 5,199

Re: Check for non-existing columns

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?

Data never sleeps
Trusted Advisor
Posts: 1,061

Re: Check for non-existing columns

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,


Posts: 73

Re: Check for non-existing columns

Thanks, I guess the solution to using column names from dictionary will be useful as well.

Appreciate the guideline RW9 Smiley Happy

Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation