SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

making a SAS library

Reply
Contributor
Posts: 25

making a SAS library

Hello, 

 

I'm working in SAS 9.4 full edition and am trying to make a SAS data file.  I keep getting errors saying that 'in' isn't a libname or that the data file doesn't exist. My code is below. Can someone clarify the role of each piece of this code?  Below, casefile is the name of a dataset I have created. Do I need to have created a library named "in" in another step?

 

Thanks!

 

libname in 'P:\folder';

data; set in.casefile; 

run;

Trusted Advisor
Posts: 1,615

Re: making a SAS library

You haven't give a name to the dataset to create and

you missed the RUN command to close  and execute the data step

 

 data  <dsname>;

   set in.casefile; 

run;

Super User
Super User
Posts: 8,174

Re: making a SAS library

Just to add, using reserved keywords like in is not a good idea.  Use something like;

libname in_data "p:/folder";
Contributor
Posts: 25

Re: making a SAS library

Thanks so much - I changed the code (below) but it still says the case file doesn't exist. Just to confirm, the term "casefile" below refers to the temporary dataset I created and want to make into a SAS file. The library name "final" refers to what?  Do I need to create that separately?  Also, is the code below right in that final needs to be after libname as well as the first part of the set compound statement?

 

libname final 'P:\folder';

data casefile; set final.casefile; 

run;

Super User
Super User
Posts: 8,174

Re: making a SAS library

Your code (note how I format it and use the code window which is the {i} above the post window):

libname final 'P:\folder';

data casefile; 
  set final.casefile; 
run;

Assumes that in the folder p:/folder - this is a physical folder on your computer, there is a file called casefile.sas7bdat.  If that file does not exist then SAS will tell you that the dataset does not exist at that location.  If you have the dataste casefile in your work library and you want to store it to the physical location p:/folder then you need to change the items over:

libname final 'P:\folder';

data casefile; 
  set final.casefile; 
run;
Super User
Posts: 8,054

Re: making a SAS library

Is a file called

casefile.sas7bdat

in P:\folder?

 

And also make it a point to post the (whole) log of a step that fails. Use the {i} icon for posting log text, as described in https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 25

Re: making a SAS library

Posted in reply to KurtBremser

Thank you very much for responding.

 

The file casefile.sas7bdat doesn't exist yet, because that was what I was trying to make!  Do I make a SAS file first and then make it into a SAS library? I'm just confused what the difference is between a library and SAS file.  My goal here is to make the file casefile.sas7bdat.

 

Best

Laura

Super User
Super User
Posts: 8,174

Re: making a SAS library

Ok, you may want to check out the SAS help videos at:

http://video.sas.com/

 

To summarise:

A library is a pointer to a physical location on your machine.  It has a name, and the full path to the location, e.g.:

libname <name> "<path>";

 

A dataset is a physical file located either in the default work library or a library of your specifying.  If you look on your operating system file structure you would see a file in the given physical path with the file extension .sas7bdat.

 

With regards to what you post nest - how are you making that dataset?  Is it read in from another file, do you create it manually in your code?  

Super User
Super User
Posts: 7,152

Re: making a SAS library

Your description of the error does not seem to match the code you are posting. That is why copying the lines from the SAS log and pasting them into a "insert code" window in the forum will help other understand more clearly what is happening.

 

The most likely thing you are doing wrong is that your data step syntax is backwards. You have posted a data step to create a work dataset from and existing permanent dataset.  But your comments make it sound like you want to do the opposite. That you want to create a permanent dataset from and exisitng work dataset.  So if you have data named FRED that you have created in your current SAS session your could save it to a permanent dataset with code like this:

data out.fred ;
  set fred;
run;

The DATA statement defines the dataset you are creating. The SET statement references the dataset you are reading.

 

If you are really having issue with defining the libref then you should see an error in the SAS log when your run the LIBNAME statement.  For example if the directory you want to write into does not exist this what will happen.

1375  libname out 'P:\folder';
NOTE: Library OUT does not exist.

This means there is either no P: drive on the machine where SAS is running, or there no directory named 'folder' in the root node of the disk.  Make sure that the machine you are running SAS on has access to the location you want to write. 

 

Note if you are using SAS University Edition then SAS is running in a virtual machine and the only directories it can see are those you have shared with it. Also the path to those directories will be those defined by how you shared them when you defined the virtual machine.  SAS UE is running under unix so all paths will be unix paths.  

libname out '/folders/myfolders/subfolder';

 

Ask a Question
Discussion stats
  • 8 replies
  • 113 views
  • 0 likes
  • 5 in conversation