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


 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 1565 views
  • 0 likes
  • 2 in conversation