BookmarkSubscribeRSS Feed
doylejm
Fluorite | Level 6

I have my students using SAS OnDemand for some simple tasks.  Is it really necessary to create a library and a LIBNAME for the datafile?  I uploaded a .csv file to a folder in my OnDemand folders, and then use the path and filename in the PROC IMPORT DATAFILE" " command as shown below.  I typically do the same thing with SAS on the PC.  I guess I am asking why I need a Library and LIBNAME for a simple program that imports a single, simple datafile?  Doesn't the path do the same thing....why the extra steps? 

Thank you

doylejm

 

 

PROC IMPORT DATAFILE="/home/doylejm/Ec385S19/house.csv"
DBMS=csv
OUT=mydat replace;
RUN;

PROC CONTENTS;
RUN;

DATA mydat2;
SET mydat;

NEWPRICE = PRICE*1000;

PROC PRINT;
TITLE 'TABLE 4.1 HOUSE PRICES';
RUN;

3 REPLIES 3
Reeza
Super User
You don't need one, but it's helpful for avoiding to have to re-read the same data set every time.
Tom
Super User Tom
Super User

A LIBNAME statement is used for a different thing than the DATAFILE= option on PROC IMPORT.

 

There is a big difference between storing a SAS dataset and storing a delimited text file, such as a CSV file. 

A CSV file does not contain any metadata about the variables.  At best it has a header row that can be used as source for guessing what names to use for the variables.

 

A SAS dataset will allow you to store the variable type, length. Attach any formats or labels to the variables.

Then when you want to use it again you can skip the step of converting the text file into data.  Instead you can use a libname statement to create a libref that points to the folder that contains the dataset.  Or you can just skip the LIBNAME statement and use the name of the file that contains the dataset.

 

So on day 1 you run this code:

PROC IMPORT
  DATAFILE="/home/doylejm/Ec385S19/house.csv" DBMS=csv
  OUT="/home/doylejm/Ec385S19/house"  replace
;
RUN;

Then on day 1,2,3,..... you can just start with this code:

data for_print;
  set "/home/doylejm/Ec385S19/house"  ;
  newprice = price*100;
run;

proc print data=for_print;
title  'TABLE 4.1 HOUSE PRICES';
run;
title;

 

 

ballardw
Super User

Any SAS data set is always stored in a Library somewhere. If you only use a one level name the default is the WORK library which means that the data set will be removed at the end of the SAS session by default. So assigning a specific library location other than work means that you can continue where you left off and all of the data is available after a libname statement is used to reference the location(s). There are several ways depending on your installation to have libraries assigned at start of your SAS session.

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 543 views
  • 0 likes
  • 4 in conversation