BookmarkSubscribeRSS Feed
noobs
Calcite | Level 5


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
Calcite | Level 5

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

Appreciate the guideline RW9 Smiley Happy

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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