DATA Step, Macro, Functions and more

Issue in using CALCULATED VARIABLE in proc update SET statement

Reply
New Contributor
Posts: 3

Issue in using CALCULATED VARIABLE in proc update SET statement

Hi

I m using below query


proc sql;

update Work.Sim_re_BERM

set L9BE_C=max(0,L9_C*(L9BE/L9)),

L9RM_C=L9_C - calculated L9BE_C;

Quit;

This is throwing an ERROR: The illegal use of a CALCULATED variable has been detected in an UPDATE statement.


Respected Advisor
Posts: 4,644

Re: Issue in using CALCULATED VARIABLE in proc update SET statement

That query makes no sense to me. What are you trying to do?   - PG

PG
New Contributor
Posts: 3

Re: Issue in using CALCULATED VARIABLE in proc update SET statement

Sorry, I am not getting your questions

L_* are columns of the table Work.Sim_re_BERM.

Setting L9BE_C based on calculation max(0,L9_C*(L9BE/L9))

And L9RM_C based difference between L9_C on CALCUALTED L9BE_C.

Respected Advisor
Posts: 4,644

Re: Issue in using CALCULATED VARIABLE in proc update SET statement

OK, maybe I get it now. Have you tried getting rid of CALCULATED :

proc sql;

update Work.Sim_re_BERM

set

     L9BE_C = max(0, L9_C*(L9BE/L9)),

     L9RM_C = L9_C - max(0, L9_C*(L9BE/L9));

Quit;


PG

PG
New Contributor
Posts: 3

Re: Issue in using CALCULATED VARIABLE in proc update SET statement


it perfectly works. But would like to understand whats wrong in using CALCUALTED variable like that Smiley Sad

Respected Advisor
Posts: 4,644

Re: Issue in using CALCULATED VARIABLE in proc update SET statement

SQL is a formal language with very strict syntax. That is very different from natural languages which are much more flexible but also more prone to misinterpretation. I think the UPDATE query is made such that every assignment (L9BE_C =, L9RM_C =, etc) clause can be treated separately (and thus, in parallel).

PG

PG
Ask a Question
Discussion stats
  • 5 replies
  • 257 views
  • 0 likes
  • 2 in conversation