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

Hello team,

 

I created a libname for a file which exists in SAS.

 

I get an error message that the libname doesn't exist.

 

Should I create a libname for a file which already exist in SAS?

 

Please advise me.

 

Regards,

Blue blue

Blue Blue
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

I created a libname for a file which exists in SAS.

 

I get an error message that the libname doesn't exist.

Not sure what you mean here. If the file is already in SAS, it doesn't need a libname. (Libnames are for folders, not files) Please show us your code, and a screen capture that shows the file as it appears in SAS.

--
Paige Miller

View solution in original post

10 REPLIES 10
PaigeMiller
Diamond | Level 26

I created a libname for a file which exists in SAS.

 

I get an error message that the libname doesn't exist.

Not sure what you mean here. If the file is already in SAS, it doesn't need a libname. (Libnames are for folders, not files) Please show us your code, and a screen capture that shows the file as it appears in SAS.

--
Paige Miller
GN0001
Barite | Level 11

Hello,

Yes, I misspelled the name of the folder.

I didn't know we shouldn't create a libname for a folder that already exist in SAS. Thanks for your input.

Anyway, it doesn't allow me to read from the file that already exists in SAS:

 

data mydata;
set membertable (obs=100);
Run;

The error I get is:

File work.membertable doesn't exist.

 

The folder is in SAS, but the backend is unix server.

Blue blue

Blue Blue
Tom
Super User Tom
Super User

@GN0001 wrote:

Hello,

Yes, I misspelled the name of the folder.

I didn't know we shouldn't create a libname for a folder that already exist in SAS. Thanks for your input.

Anyway, it doesn't allow me to read from the file that already exists in SAS:

 

data mydata;
set membertable (obs=100);
Run;

The error I get is:

File work.membertable doesn't exist.

 

The folder is in SAS, but the backend is unix server.

Blue blue


What is the file you are trying to access?  If you have a SAS datasets on disk you can either assign a libref that points to the directory that contains the file using a LIBNAME statement or LIBNAME() function and reference the file using a "two level" name.  (Note if you already have a defined libref just use that libref) 

libname mylib 'mydirectoryname';
data mydata;
  set mylib.membertable (obs=100);
run;

Or just reference the file by using its physical name in quotes.

data mydata;
  set "mydirectoryname/membertable" (obs=100);
run;

Note that SAS will silently make a libref pointing to the directory for you without telling you.

GN0001
Barite | Level 11

Hello,

Actually the data exists in SAS but without libname, I can't read from that dataset.

Regards,

Blue Blue

Blue Blue
Reeza
Super User

Not technically correct you can reference a file with the full path.

 

data want;
set '/home/fkhurshed/Demo1/class.sas7bdat';
run;

@GN0001 wrote:

Hello,

Actually the data exists in SAS but without libname, I can't read from that dataset.

Regards,

Blue Blue


 

Tom
Super User Tom
Super User

Unless your want to use a libref engine that access many members in a single file (like XPORT or XLSX) then the libname should point to the folder that contains the file not the actual file that is the SAS dataset.

 

So if SAS is running on Unix and you have a file named mydata.sas7bdat in a directory named \home\myname\myfiles then your SAS code might look like:

libname XXX '\home\myname\myfiles';
proc contents data=xxx.mydata;
run;

 

GN0001
Barite | Level 11

Hello,

Still, I can't read the file if I don't create a libname statement. SAS is running on unix.

Regards,

blue blue

Blue Blue
Reeza
Super User

@GN0001 wrote:

Hello team,

 

I created a libname for a file which exists in SAS.

 

I get an error message that the libname doesn't exist.

 

Should I create a libname for a file which already exist in SAS?

 

Please advise me.

 

Regards,

Blue blue


You did something wrong. Show your work if you want to know where specifically you went wrong.

GN0001
Barite | Level 11

one of the folders in the path in the libname is misspelled.

Instead of QA, I spelled AQ.

 

 

Thanks,

Blue Blue

Blue Blue

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 10 replies
  • 4205 views
  • 4 likes
  • 5 in conversation