Syntax help with PROC SQL statement

Accepted Solution Solved
Reply
Contributor
Posts: 44
Accepted Solution

Syntax help with PROC SQL statement

PROC SQL ;
CREATE TABLE WORK.query AS SELECT DISTINCT (CLM_DRG_CD) FROM
INP.INP_CLAIMSK_LDS2016 WHERE CLM_DRG_CD='469' OR CLM_DRG_CD='470'
COUNT(CLM_DRG_CD) AS COUNT GROUP BY CLM_DRG_CD;
CONTENTS DATA=WORK.query OUT=WORK.details;
RUN;

 

 

 

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
61
62 PROC SQL ;
63 CREATE TABLE WORK.query AS SELECT DISTINCT (CLM_DRG_CD) FROM
64 INP.INP_CLAIMSK_LDS2016 WHERE CLM_DRG_CD='469' OR CLM_DRG_CD='470'
65 COUNT(CLM_DRG_CD) AS COUNT GROUP BY CLM_DRG_CD;
_____
22
76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, AND, EQ,
EQT, GE, GET, GROUP, GT, GTT, HAVING, LE, LET, LT, LTT, NE, NET, OR, ORDER, ^=, |, ||, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
66 CONTENTS DATA=WORK.query OUT=WORK.details;
________
180
ERROR 180-322: Statement is not valid or it is used out of proper order.

67 RUN;
NOTE: PROC SQL statements are executed immediately; The RUN statement has no effect.
68
69
70 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
83


Accepted Solutions
Solution
‎03-02-2018 12:54 PM
Super User
Posts: 23,771

Re: Syntax help with PROC SQL statement

Format your code for starters will help to see what doesn't align (and don't use all caps for coding or anything really except emphasis)

 

proc sql ;
create table work.query as 
select distinct (clm_drg_cd) from
inp.inp_claimsk_lds2016 
where clm_drg_cd='469' or clm_drg_cd='470'
count(clm_drg_cd) as count /*<- in the wrong place*/
group by clm_drg_cd;
contents data=work.query out=work.details;
run;

This is probably closer to what you're trying to do:

proc sql ;
create table work.query as 
select distinct (clm_drg_cd) , count(clm_drg_cd) as count 
from
inp.inp_claimsk_lds2016 
where clm_drg_cd='469' or clm_drg_cd='470'
group by clm_drg_cd;
quit;


proc contents data=work.query out=work.details;
run;

View solution in original post


All Replies
Solution
‎03-02-2018 12:54 PM
Super User
Posts: 23,771

Re: Syntax help with PROC SQL statement

Format your code for starters will help to see what doesn't align (and don't use all caps for coding or anything really except emphasis)

 

proc sql ;
create table work.query as 
select distinct (clm_drg_cd) from
inp.inp_claimsk_lds2016 
where clm_drg_cd='469' or clm_drg_cd='470'
count(clm_drg_cd) as count /*<- in the wrong place*/
group by clm_drg_cd;
contents data=work.query out=work.details;
run;

This is probably closer to what you're trying to do:

proc sql ;
create table work.query as 
select distinct (clm_drg_cd) , count(clm_drg_cd) as count 
from
inp.inp_claimsk_lds2016 
where clm_drg_cd='469' or clm_drg_cd='470'
group by clm_drg_cd;
quit;


proc contents data=work.query out=work.details;
run;
☑ This topic is solved.

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

Discussion stats
  • 1 reply
  • 118 views
  • 0 likes
  • 2 in conversation