BookmarkSubscribeRSS Feed
noobs
Fluorite | Level 6


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

3 REPLIES 3
LinusH
Tourmaline | Level 20

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
TomKari
Onyx | Level 15

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

noobs
Fluorite | Level 6

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

Appreciate the guideline RW9 Smiley Happy

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1365 views
  • 0 likes
  • 3 in conversation