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

Hi all,

This is a beginner's question

I am trying to merge 2 SAS datasets into one by ID with a PROC SQL, but it seems that my file reference is wrong.

The log says that my file doesn't exist.

Would anybody know what is wrong with this code?

 

libname ABC  '/global/home/XXX';

filename K1 '/global/home/XXX.sas7bdat';

filename K2 '/global/home/XXYXX.sas7bdat';

proc sql;
select 	k.ID as A_BBB,
 	r.ID as B_BBB, 
AGE , GENDER, HEIGHT, CITY , PHONE NUMBE
 
FROM 	ABC.K1 as K,
 	ABC.K2 as R	
WHERE K.ID eq r.ID;
QUIT;

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You need a LIBNAME statement, not a FILENAME statement. 

 

You create a reference to the folder with the files and then use them as LibName.DataSetName

 

Check if the following works, if not, please post your full log - you may want to check that Phone Number is spelled correctly for example. Usually you don't have spaces in the variable name as well as you're missing the R. 

 

You probably want to replace it with: 'phone number'n or phoneNumber depending on variable name. 

 

 

libname ABC  '/global/home/';


proc sql;
select 	k.ID as A_BBB,
 	r.ID as B_BBB, 
AGE , GENDER, HEIGHT, CITY , PHONE NUMBE
 
FROM 	ABC.K1 as K,
 	ABC.K2 as R	
ON K.ID eq r.ID;
QUIT;

 

 


@Dublin187 wrote:

Hi all,

This is a beginner's question

I am trying to merge 2 SAS datasets into one by ID with a PROC SQL, but it seems that my file reference is wrong.

The log says that my file doesn't exist.

Would anybody know what is wrong with this code?

 

libname ABC  '/global/home/XXX';

filename K1 '/global/home/XXX.sas7bdat';

filename K2 '/global/home/XXYXX.sas7bdat';

proc sql;
select 	k.ID as A_BBB,
 	r.ID as B_BBB, 
AGE , GENDER, HEIGHT, CITY , PHONE NUMBE
 
FROM 	ABC.K1 as K,
 	ABC.K2 as R	
WHERE K.ID eq r.ID;
QUIT;

Thank you


 

View solution in original post

1 REPLY 1
Reeza
Super User

You need a LIBNAME statement, not a FILENAME statement. 

 

You create a reference to the folder with the files and then use them as LibName.DataSetName

 

Check if the following works, if not, please post your full log - you may want to check that Phone Number is spelled correctly for example. Usually you don't have spaces in the variable name as well as you're missing the R. 

 

You probably want to replace it with: 'phone number'n or phoneNumber depending on variable name. 

 

 

libname ABC  '/global/home/';


proc sql;
select 	k.ID as A_BBB,
 	r.ID as B_BBB, 
AGE , GENDER, HEIGHT, CITY , PHONE NUMBE
 
FROM 	ABC.K1 as K,
 	ABC.K2 as R	
ON K.ID eq r.ID;
QUIT;

 

 


@Dublin187 wrote:

Hi all,

This is a beginner's question

I am trying to merge 2 SAS datasets into one by ID with a PROC SQL, but it seems that my file reference is wrong.

The log says that my file doesn't exist.

Would anybody know what is wrong with this code?

 

libname ABC  '/global/home/XXX';

filename K1 '/global/home/XXX.sas7bdat';

filename K2 '/global/home/XXYXX.sas7bdat';

proc sql;
select 	k.ID as A_BBB,
 	r.ID as B_BBB, 
AGE , GENDER, HEIGHT, CITY , PHONE NUMBE
 
FROM 	ABC.K1 as K,
 	ABC.K2 as R	
WHERE K.ID eq r.ID;
QUIT;

Thank you


 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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