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
;

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 542 views
  • 3 likes
  • 3 in conversation