BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mona4u
Lapis Lazuli | Level 10

I'm trying to create macros in sql and I'm also trying to create a table and that my code and the error that I got 

 

proc sql ;
create table &visit.2 as
select count (distinct internal_visit_id) AS counttime, 1360 AS TIME_POINT_CONTRACTED
from &visit.1
where Earliest_Visit_Date ne .
select counttime , TIME_POINT_CONTRACTED into :counttimet, :timecont from &visit.2;
quit;

 

 

71 proc sql ;
72 create table &visit.2 as
73 select count (distinct internal_visit_id) AS counttime, 1360 AS TIME_POINT_CONTRACTED
74 from &visit.1
75 where Earliest_Visit_Date ne .
76 select counttime into :counttimet from &visit.2;
______
22
76
ERROR 22-322: Syntax error, expecting one of the following: <, <=, <>, =, >, >=, EQ, EQT, EXCEPT, GE, GET, GT, GTT, INTERSECT, LE,
LET, LT, LTT, NE, NET, UNION, ^=, ~=.
 
ERROR 76-322: Syntax error, statement will be ignored.
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You’re missing the semicolon to end your first SELECT statement.

 

View solution in original post

3 REPLIES 3
Reeza
Super User

You’re missing the semicolon to end your first SELECT statement.

 

ballardw
Super User

if the purpose of the second select statement is to restrict the data then it is 1) out of order and 2) likely needs parentheses:

 

Or you are missing a semicolon between two separate queries

proc sql ;
create table &visit.2 as 
select count (distinct internal_visit_id) AS counttime, 1360 AS TIME_POINT_CONTRACTED
from &visit.1
where Earliest_Visit_Date ne . ;

select counttime , TIME_POINT_CONTRACTED into :counttimet, :timecont from  &visit.2;    
quit; 
Tom
Super User Tom
Super User

I find that you can prevent some of these types of mistakes by getting in the habit of formatting multi-line statements similar to how you would format a multiple line DO/END block. 

If 0=nmiss(x,y) then do;
   diff = x-y ;
   percent = diff/y ;
end;

That is place the termination code (the semi-colon) on the last line by itself.

proc sql ;
create table &visit.2 as 
  select count (distinct internal_visit_id) AS counttime
      , 1360 AS TIME_POINT_CONTRACTED
  from &visit.1
  where Earliest_Visit_Date ne .
;
select counttime , TIME_POINT_CONTRACTED into :counttimet, :timecont 
  from  &visit.2
;
quit; 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 3 replies
  • 480 views
  • 2 likes
  • 4 in conversation