BookmarkSubscribeRSS Feed
BWDAWG
Obsidian | Level 7

New to SAS. For some reason creating and using permanent datasets completely confuses me and I cannot seem to get. Read about it and watched plenty of youtube videos but still confused.

 

Lets say I want to create a permanent SAS dataset, to test this I entered the following into SAS:

 

Libname perm "myfilepath";

data perm.test;

input id age;

datalines;

1 34

2 45

3 23

;

run;

 

So i run this program and I see the folder perm with file test in the explorer window. When I close out of sas and reopen it, the folder is gone. Is this supposed to happen or is there something else I am supposed to do.

 

Also, when I want to do a test to use the permanent sas dataset I created, I open sas and try to run a frequencies test with the following:

 

Proc freq data=perm.test;

run;

 

But nothing happens. But when I do the following, it works:

 

Libname perm "myfilepath";

proc freq data=perm.test;

run;

 

Do I have to re-enter to libname statement everytime I want to use my permanent dataset? This doesn't seem right? I feel like it defeats the purpose of creating a permanent dataset. I though I could just reference the dataset as I did above. Why is the file not in the explorer window when I close and reopen sas. Does anyone have a link to some source about this that is clear?

7 REPLIES 7
PaigeMiller
Diamond | Level 26

yes, you have to run the libname statement every time you launch SAS

 

OR

 

put the libname statement into your autoexec.sas file

--
Paige Miller
BWDAWG
Obsidian | Level 7

Ok thank for the reply Paige. But why can't I see the permanent folder or dataset anywhere? It is not in the location that I created it with using a filepath on my computer, and it is not in sas explorer window. Overtime I'm sure I will have multiple folders with multiple datasets in them and will not be able to remember everything when I want to reference a dataset.

BWDAWG
Obsidian | Level 7

Nevermind, I see now that the Libname statement does not actually create a new folder on your computer. 

ballardw
Super User

@BWDAWG wrote:

Nevermind, I see now that the Libname statement does not actually create a new folder on your computer. 


Actually that depends. The option DLCREATEDIR will have a LIBNAME statement create a directory (folder) in versions of SAS 9.3 and later. The default in UNIX and Windows has the option NODLCREATEDIR set so by default in those operating systems in wouldn't. The option might be restricted by a site administrator though.

 

 

PaigeMiller
Diamond | Level 26

@BWDAWG wrote:

Ok thank for the reply Paige. But why can't I see the permanent folder or dataset anywhere? It is not in the location that I created it with using a filepath on my computer, and it is not in sas explorer window. Overtime I'm sure I will have multiple folders with multiple datasets in them and will not be able to remember everything when I want to reference a dataset.


It helps if you don't pick some random location for your permanent data sets. I have a folder for each project, and sometimes folders underneath for each subproject, and also a subfolder for code and a subfolder for data sets. If I am working on project CRB, then everything, including code and datasets and outputs are in the CRB folder or appropriate subfolders.

 

As stated above, you can place the libname statement in your autoexec.sas file, and then you don't have to remember this information. SAS will remember it for you. Use the computer software for what it is good at, rather than rely on your own memory.

--
Paige Miller
Ksharp
Super User

Press 'New Library' button at top of sas window, and Enter name PERM and path 'myfilepath',

and select 'Enable at StartUp' box.

 

After that you could refer to PERM, no need add a libname statement everytime.

FreelanceReinh
Jade | Level 19

In addition to the good advice that has already been provided: It's not bad to have the required LIBNAME statements in the code of a program which refers to permanent datasets, in particular if the physical locations of the datasets vary between projects (cf. Paige Miller's post). This way you know immediately where to look for the datasets the program refers to (e.g. when you -- or someone else -- open an "old" program).

 

Therefore it's not uncommon in practice (not in all companies, though) to start a program, after the program header, with LIBNAME statements, OPTIONS statements, %INCLUDE statements or whatever is necessary to prepare the session for the subsequent code.

 

That said, in a private learning environment it's certainly convenient to use the technique Ksharp has suggested (which stores the libref assignment in the SAS registry -- if possible).

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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