4

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.

Llex
  • 1,770
  • 1
  • 12
  • 27
user3298004
  • 185
  • 2
  • 3
  • 10
  • If you're using the query builder you're stuck with the code it generates, but I assume if you fix it one place in the query builder it will also fix elsewhere. – Reeza Aug 20 '19 at 15:32

2 Answers2

6

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
Llex
  • 1,770
  • 1
  • 12
  • 27
3

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

user667489
  • 9,501
  • 2
  • 24
  • 35