Hi!
I am trying to write a proc sql to compute a check variabile that should be ugual to zero, but SAS return to me this error:
ERROR: It appears that the CALCULATED variable gross_cam_t0 was referenced before it was defined.
ERROR: It appears that the CALCULATED variable gross_cam_t1 was referenced before it was defined.
ERROR: The following columns were not found as CALCULATED references in the immediate query: gross_cam_t0, gross_cam_t1.
These are my two input dataset
data have_1;
input id $2. gross_cam_t0 gross_cam_t1;
datalines;
A1 10 5
B2 1 1
C3 8 11
;
run;
data have_2;
input delta;
datalines;
-5
0
3
;
run;This is what I would like to have
data temp;
input gross_cam_t0_tot gross_cam_t1_tot delta_tot;
datalines;
19 17 -2
;
run;
data want;
set temp;
check_ugual_zero = sum(gross_cam_t0_tot,delta_tot,-gross_cam_t1_tot);
run;And this is my SAS code that dosen't work
proc sql;
select sum(gross_cam_t0) as gross_cam_t0 ,
sum(gross_cam_t1) as gross_cam_t1
from have_1 outer union corr
select sum(delta) as delta,
calculated gross_cam_t0 + calculated delta - calculated gross_cam_t1 as check_ugual_zero
from have_2;
quit;If I am not clear pleas write me and I'll give more detail.
Plese help me to fix this code. Thanks a lot!
Daniel
Try this:
proc sql;
create table want as
select
sum(gross_cam_t0) as gross_cam_t0 ,
sum(gross_cam_t1) as gross_cam_t1,
(select sum(delta) from have2) as delta,
calculated gross_cam_t0 + calculated delta - calculated gross_cam_t1 as check_ugual_zero
from have_1
;
quit;
Untested, posted from my tablet.
Try this:
proc sql;
create table want as
select
sum(gross_cam_t0) as gross_cam_t0 ,
sum(gross_cam_t1) as gross_cam_t1,
(select sum(delta) from have2) as delta,
calculated gross_cam_t0 + calculated delta - calculated gross_cam_t1 as check_ugual_zero
from have_1
;
quit;
Untested, posted from my tablet.
Great! thanks for your help!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.