BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ccasagran737
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

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.

Ccasagran737
Fluorite | Level 6

Great! thanks for your help!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1776 views
  • 0 likes
  • 2 in conversation