Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing one computed column from another

I'm using SAS Enterprise Guide 7.1 and i'm having a problem with something that seems fairly basic. I'll simplify the problem but fundamentally I have one computed column (Computed_column1) that uses a CASE/WHEN statement e.g.

CASE
WHEN x > y THEN "TRUE"
ELSE "FALSE"
END

I'd like to reference the first computed column in a second computed column (Computed_column2) but instead of referring to the computed column name the advanced expression tab in the query builder pulls through all of the contents from the first computed column. Therefore if i need to change the first column i'll have to change the second one also.

So my second computed column looks something like this:

CASE
WHEN (CASE WHEN x > y THEN "TRUE" ELSE "FALSE" END) > z THEN "TRUE"
ELSE "FALSE"
END

When i'd like it to be some type of dynamic reference like:

CASE
WHEN Computed_column1 > z THEN "TRUE"
ELSE "FALSE"
END

This way if the first computed column changes the second will also. Is this not possible?

Cheers in advance.

like image 499
user3298004 Avatar asked Dec 13 '22 10:12

user3298004


2 Answers

You can read more about calculated variables here (paragraph name "THE CALCULATED OPTION ON THE SELECT"). In your case you should write:

CASE
WHEN CALCULATED Computed_column1 > z THEN "TRUE"
ELSE "FALSE"
END
like image 153
Alexey Sigida Avatar answered Dec 31 '22 17:12

Alexey Sigida


This works almost as exactly as you've imagined it. Just use calculated rather than computed.

like image 23
user667489 Avatar answered Dec 31 '22 18:12

user667489