BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi ,

could you pleasae suggest , if something is in the Work library , can it be recalled when i use SAS again , is it possible to have this file in the location of , say , C drive

kind regards ,
mark
2 REPLIES 2
Doc_Duke
Rhodochrosite | Level 12
Everything that is in the work library is wiped out when you exit the SAS session. You can specify where the work library is placed, either as a default for each use of SAS or when SAS starts up. Regardless of where it is placed, SAS will wipe it clean on exit.

You should read the Windows Companion for your version of SAS to find the specifics.

Doc Muhlbaier
Duke
Cynthia_sas
SAS Super FREQ
Hi:
The automatic library, WORK, exists for the duration of a single SAS session. If you use the WORK library, usually by referencing or creating a dataset with a one level name, that WORK library goes away when your SAS session ends. So the quick answer to your question is NO, if you store data in the WORK library, that WORK copy of the dataset will go away when the SAS session is over.

For example, if you do this:
[pre]

data a;
x=1;
y=2;
z=3;
output;
x=4;
y=5;
z=6;
output;
run;

proc print data=a;
run;
[/pre]

You have just created WORK.A as a -TEMPORARY- SAS dataset. When your SAS session is over, WORK.A will go away. If you want to keep or store the dataset in a permanent library (such as in the c:\fred location), then you need to make sure that you copy or otherwise create a permanent dataset:
[pre]

**Option 1: Create WORK.A and then use PROC SORT to make KEEP.A;
libname keep 'c:\fred';

data a;
x=1;
y=2;
z=3;
output;
x=4;
y=5;
z=6;
output;
run;

proc sort data=work.a out=keep.a;
by x;
run;

proc print data=keep.a;
run;

*** Option 2: Just make KEEP.A initially and then during your SAS session refer to the data by the 2-level name;

libname keep 'c:\fred';

data keep.a;
x=1;
y=2;
z=3;
output;
x=4;
y=5;
z=6;
output;
run;

proc print data=keep.a;
run;
[/pre]

So now, in one session, you've made KEEP.A. Then you log off your SAS session. The next time you log on, you have to re-issue your LIBNAME statement again in order to have SAS "find" the data (or else you have to set up some startup code that will always issue your LIBNAME statement for you).

If you log off from your SAS session without saving your data into a permanent library, then you have to start at the beginning again to recreate your data or reread your input file.

Just remember that anytime you use a 1-level name such as:
[pre]
data XXX;
proc print data=XXX;
proc .... out=XXX;
[/pre]

Then the default location for that file is the WORK library. So
[pre]
data XXX; is the same as having
data WORK.XXX;
[/pre]

For you to use a 2-level name, you either have to use the SASUSER library (which is usually a permanent library) OR you have to issue an explicit LIBNAME statement which establishes a "nickname" or LIBREF (library reference) like this:
[pre]
libname fredlib 'c:\fred';
libname joelib 'c:\joe';
libname wombat 'c:\acct\sasdata';
[/pre]

In the above examples, FREDLIB, JOELIB and WOMBAT are the nicknames or the LIBREFs. They each point to a different physical Windows directory. If you save SAS datasets into a Windows (or Unix) directory, and you go look at the directory folder, you might see file names like:
[pre]
c:\fred\A.sas7bdat
c:\joe\B.sas7bdat
c:\acct\sasdata\acct2010.sas7bdat
[/pre]

SAS7BDAT is the file extension given on Windows and UNIX to SAS datasets. Assuming that I have established the following LIBNAME statements in my SAS session:
[pre]
libname fredlib 'c:\fred';
libname joelib 'c:\joe';
libname wombat 'c:\acct\sasdata';
...then I could reference those datasets by using the following 2-level names...

FREDLIB.A
JOELIB.B
WOMBAT.ACCT2010
[/pre]

But if I did something like this in my SAS session:
[pre]

proc sort data=WOMBAT.ACCT2010 out=ACCT2010JAN;
where month = 1;
run;
[/pre]

This means I've created a WORK dataset WORK.ACCT2010JAN, as a subset of the permanent WOMBAT.ACCT2010 data. If I forget to save ACCT2010JAN before I close my SAS session, then the next time I log on, I have to recreate it again.
[/pre]

So that's a long explanation. My suggestion is that you read some of the documentation about SAS datasets and the concepts of a SAS library -- both permanent and temporary.
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/a000086013.htm
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a002316278.htm
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a000986902.htm
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a000930616.htm
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a002316280.htm
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a000998603.htm

In order to post forum questions, you had to set up a name and password. When you access the documentation pages, if you are prompted for an id and password, just use the id and password that you use to post to the forum. The online documentation is very good and is worth reading.

cynthia

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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