Problem with PROC SQL function

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Problem with PROC SQL function

Hi everyone, I got a problem with the SUM function from SQL code, I can´t sum two columns made with a query: Select Cod_Ex0 as A, (Select Col_0 From Table_0) as B, (Select Col_1 From Table_1) as C, Sum(B,C) as D From Table_2; The Sum function generates an error: ERROR: The following columns were not found in the contributing tables: B, C. Please help me,

Accepted Solutions
Solution
‎06-07-2016 02:10 PM
Grand Advisor
Posts: 17,342

Re: Problem with PROC SQL function

Sum(Calculated B ,Calculated C) as D

View solution in original post


All Replies
Grand Advisor
Posts: 17,342

Re: Problem with PROC SQL function

Verify that Table_2 has columns B/C.

 

Or are you you intending B/C to be your calculated columns?

Occasional Contributor
Posts: 14

Re: Problem with PROC SQL function

Yes, The B and C columns are independent from Table_2; are new calculated columns in the query, but i want make a third column add both (D).

Grand Advisor
Posts: 17,342

Re: Problem with PROC SQL function

Try adding the word CALCULATED before the two variables. 

Occasional Contributor
Posts: 14

Re: Problem with PROC SQL function

Like this? : Sum(Calculated(B),Calculated(C)) as D
Solution
‎06-07-2016 02:10 PM
Grand Advisor
Posts: 17,342

Re: Problem with PROC SQL function

Sum(Calculated B ,Calculated C) as D
Occasional Contributor
Posts: 14

Re: Problem with PROC SQL function

Thank you my friend, works!! Problem resolve!!
Valued Guide
Posts: 505

Re: Problem with PROC SQL function

Are you trying to do somthing like this

 

proc sql;
create
table abc as
select
status
,(select sum(height) from sashelp.class) as hgt
,(select sum(weight) from sashelp.class) as wgt
,sum(calculated hgt,calculated wgt) as sumhgtwgt
from
sashelp.heart
;quit;

 

/*

the selects cannot result in mutiple rows

 

up to 40 obs WORK.ABC total obs=5,209

Obs STATUS HGT WGT SUMHGTWGT

1 Dead 1184.4 1900.5 3084.9
2 Dead 1184.4 1900.5 3084.9
3 Alive 1184.4 1900.5 3084.9
4 Alive 1184.4 1900.5 3084.9
5 Alive 1184.4 1900.5 3084.9
*/

Occasional Contributor
Posts: 14

Re: Problem with PROC SQL function

That´s right @rogerjdeangelis , The Calculated solve my problem hehehe, Thank you too!!
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 481 views
  • 0 likes
  • 3 in conversation