DATA Step, Macro, Functions and more

libname statement

Reply
Occasional Contributor
Posts: 6

libname statement

I need some help and I know this is a super basic question, but i am stumped.  I can create a library in SAS, and then import a dataset into the library from the dropdown menu.  However, when I try to do a libname statement, I get an error.

 

here is example code:

 

libname PROJECT 'P:\Users\amrowland\Desktop\My Documents\organics.csv';

 

304 libname PROJECT 'P:\Users\amrowland\Desktop\My Documents\organics.csv';

NOTE: Library PROJECT does not exist.

 

And under active libraries it has the regular SAS libraries included as well as the project library i created, so I can see the library sitting there.

 

Can anyone help me out, please?

 

Adam

 

 

Respected Advisor
Posts: 4,173

Re: libname statement

Posted in reply to BoboTheFool

In general a LIBNAME statement needs to point to a "container" (like a folder) which contains tables. 

 

You've got a .csv file and for this you need to define a FILENAME and then a SAS data step or Proc Import which reads this textual file and stores the result in a table.

Occasional Contributor
Posts: 6

Re: libname statement

So here is what I did -

 

filename project 'P:\Users\amrowland\My Documents\organics.csv';

proc import file=project out=P1 dbms=csv;

run;

 

So it sends the CSV file P1 to the work file, under Work.P1.

libname is still not working at all for me.  I don't know why it is so difficult, as it seems fairly easy.

SAS Super FREQ
Posts: 8,868

Re: libname statement

[ Edited ]
Posted in reply to BoboTheFool

The LIBNAME statement should only be used to point to permanent SAS datasets. Your CSV file is NOT a permanent SAS dataset.

Try this...assuming that your My Documents folder exists, as you show your FILENAME statement, then you can also define a LIBNAME there:

libname perm 'P:\Users\amrowland\My Documents';

** Make permanent SAS dataset on P drive folder;
data perm.newclass;
set sashelp.class;
run;

** run reports against permanent data;
proc contents data=perm.newclass;
run;

proc print data=perm.newclass;
run;

Then, once the above works for you, you can change your OUT= in the PROC IMPORT to be OUT=perm.p1 and then your CSV file will be transformed into SAS dataset format. Then, the above LIBNAME statement will point to that location for you.

cynthia

Occasional Contributor
Posts: 6

Re: libname statement

Posted in reply to Cynthia_sas

It gives me the error that I don't have the permission to do that.  Can I not create a library to send my dataset to in order to work on it?  Does it need to be a permanent library that I create?  This is super confusing - I am just trying to create a library in which to store my CSV file to do some data mining operations on it, and later down the road am supposed to create another library to store some histograms.  I thought it was not going to be difficult, as I am pretty new to SAS, but it seems downright difficult.

 

libname project 'P:\Users\amrowland\My Documents';

 

ERROR: User does not have appropriate authorization level for library PROJECT.

ERROR: Error in the LIBNAME statement

 

I used perm first and got the same error message.

Super User
Super User
Posts: 7,988

Re: libname statement

Posted in reply to BoboTheFool

Are you using SAS University Edition, or what type of SAS are you using?  @Cynthia_sas's code should work fine (assuming there is a folder called: P:\Users\amrowland\My Documents - which you will change to your folder), however that sasumes you are using the full SAS, if you are using UE or one of the other packages then this will be different.

SAS Super FREQ
Posts: 8,868

Re: libname statement

The fact that the FILENAME statement works using the P drive location indicates that there is READ access to the P: drive location. But not being able to have write permission to that location is not something that SAS can fix.

If you do NOT have WRITE permission to the P drive location, then the LIBNAME statement will NOT work for you to make a dataset there. I recommend that you speak with someone who is the administrator on your system to help you find a folder that you can WRITE to.

For example, if you open Notepad on your computer (Start --> All Programs --> Accessories --> Notepad) and just type a few lines of anything into the file and do a File -- Save As--> can you save a TXT file to that location? Or, alternately, can you make a folder on your C: drive to which you have write access?

If, and only if, you are using SAS University Edition you would need to use a shared folders location and then your LIBNAME statement would be something like this:
libname project '/folders/myfolders/somedir';

But IF you were running the SAS University Edition, you should NOT have been able to read from your P: drive, which is why I suspected that you have a local install of either SAS or Enterprise Guide as an interface to SAS and you have READ access to certain directories, but not WRITE access.

You have to figure out your system and where you can WRITE. Just trying the the LIBNAME statement over and over again won't work without WRITE access. And only someone who understands your system permissions can help you figure out a folder/directory where you have WRITE access.

When you find a folder that you can save to using Notepad, that is a folder that you have WRITE access to.

cynthia
Ask a Question
Discussion stats
  • 6 replies
  • 401 views
  • 0 likes
  • 4 in conversation