BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
smg3141
Obsidian | Level 7

Hello!

 

I'm attempting to do an inner join on multiple tables. This code is within a %DO loop with n as the variable. 

 

%let file1=datahave1;

%let file2=datahave2;

.

.

.

%let file10=datahave10;

%let numoffiles=10;

libname input "path";

 

%macro formatex;
%do n=1 %to &numoffiles;

 

proc sql;
create table name1&&file&n as
select *
from name2&&file&n a inner join input.&&file&n.._base b
on a.ssn = b.&pat_ssn and a.record_id= b.record_id
quit;
run;

 

%end;
%mend;
%formatex;

 

Right now it just runs the SQL step forever. I'm new to macros, so any help would be greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @smg3141,

 


@smg3141 wrote:

on a.ssn = b.&pat_ssn and a.record_id= b.record_id;
quit;

run;

Right now it just runs the SQL step forever.


This is because you missed the semicolon that I've inserted in red above.

 

The RUN statement can be deleted. PROC SQL doesn't need it.

View solution in original post

3 REPLIES 3
FreelanceReinh
Jade | Level 19

Hello @smg3141,

 


@smg3141 wrote:

on a.ssn = b.&pat_ssn and a.record_id= b.record_id;
quit;

run;

Right now it just runs the SQL step forever.


This is because you missed the semicolon that I've inserted in red above.

 

The RUN statement can be deleted. PROC SQL doesn't need it.

smg3141
Obsidian | Level 7
Doh! What a rookie mistake. Thank you!
Tom
Super User Tom
Super User

When writing a single statement that spans multiple lines put the semi-colon that ends it on its own line.  Like the END in a DO/END block.

Then you are less likely to forget it or insert extra ones.

create table name1&&file&n as
  select *
  from name2&&file&n a
  inner join input.&&file&n.._base b
     on a.ssn = b.&pat_ssn
    and a.record_id= b.record_id
;

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 684 views
  • 3 likes
  • 3 in conversation