BookmarkSubscribeRSS Feed
noobs
Calcite | Level 5


Hello EG Users,

I am writing simple computed columns in SAS EG that calculate Total = sum(t1.var1,t1.var2)

However, sometimes the dataset may end up not having var1 at all since this dataset is being put together after multiple filters, transpose and merges.

So is there a way to determine if the column being used in the calculation exists before it is used in the equation?

EXIST function is useful to verify if dataset exists, and not quite helpful in this scenrio.

Any reference to var1 will give me error that says

ERROR: Column var1 could not be found in the table/view identified with the correlation name T1

So does SAS Eg provide a way to check if column exists?

Thanks,

Dhanashree

3 REPLIES 3
LinusH
Tourmaline | Level 20

Not that I know of. If you want to check this, you need some kind of macro'ish logic somewhere in your flow.

Perhaps it's easier to code in some way that you always will have var1, like having a template table which append to, or doing something like

data want;

set template

     have;

run;

..Your  EG task...

Can't tell how to implement this since I know nothing of the rest of the flow, amount of user written vs Tasks etc.

Data never sleeps
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Rather than hardcoding the list of variables to add into the sum and having to check existence, why not just start with an identifiable column range, say call all the ones you do want to sum have a prefix of SUM_, then use sql to create the macro variable with these in:

proc sql;

     select     distinct NAME

     into          :LIST_OF_SUM separated by ','

     from          DICTIONARY.COLUMNS

     where         LIBNAME="your libname here"

          and        MEMNAME="your dataset here"

          and          substr(NAME,1,3)="SUM";

quit;

%put &LIST_OF_SUM.;

/* Possible output:     SUM_COL1, SUM_COL2... */

That way only variables which exist will be in your macro variable.

noobs
Calcite | Level 5

alright thanks!

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
  • 1548 views
  • 1 like
  • 3 in conversation