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;
You’re missing the semicolon to end your first SELECT statement.
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;
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.