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
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.
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.
alright thanks!
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.