02-25-2014 08:45 AM
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?
02-25-2014 09:39 AM
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
..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.
02-25-2014 10:00 AM
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:
select distinct NAME
into :LIST_OF_SUM separated by ','
where LIBNAME="your libname here"
and MEMNAME="your dataset here"
/* Possible output: SUM_COL1, SUM_COL2... */
That way only variables which exist will be in your macro variable.