I have a table built with integer values (Table X)
Column 1 Column 2
A 1
B 2
C 10
I have a secondary table (Table Y) built with Decimal variables to contain a calculated number based on Table X
proc sql;
(select sum(Column 2) from Table X where Column 1 like ('A', 'B') ) /
(select Column 2 from Table X where Column 1 = 'C');
Run;
I am trying to run this calculation but am getting an error
ERROR 22-322: Syntax error, expecting one of the following: ;, EXCEPT, INTERSECT, ORDER, OUTER, UNION.
Although you mention you have table Y, it doesn't seem to appear in your description of the problem.
Where does it come into use?
I am going to be insterting the caluclated value into Table Y. I suppose it's not relevant here because my issue is the calculation part.
Show us the log of this PROC SQL step. We need to see the entire LOG, not just the error message. To preserve the formatting and make the log readable, please click on the {i} icon and paste the log into the window that appears — do not skip this step.
Proper syntax could be:
proc sql;
create table Y as
sum((column1 like ('A', 'B'))*Column2) /
sum((column1 = 'C')*Column2) as Ratio
from X;
quit;
Or try the third step of this example:
data X;
input Column1 $ Column2;
cards;
A 1
B 2
C 10
;
proc sql;
create table Y (z num);
quit;
proc sql;
insert into Y
select
(select sum(Column2) from X where Column1 in ('A', 'B')) / Column2
from X where Column1 = 'C';
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.