Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a second temporary data library

Status
Not open for further replies.

6656

Programmer
Nov 5, 2002
104
US
Hi all,

Does anyone can give me a syntax to create a second temporary data library, which is separated from WORK.

Thanks,
Mike
 
Mike,
Where exactly do you want this library. Should it reside under the work library path? Do you want it to vanish (erase itself) after the SAS session? Please give us some more details.

I can give you a few ideas. First some background on how SAS creates & uses its temp workspace. On a Windows system (the other OS's may have a slightly dif. way) SAS will read a config file (usually SAS8.cfg in ver 8). In this file there is a path to directory that sas uses for its work directory. This becomes the root of the temp folder. SAS uses a seed to create a temp folder named '#some_number'. It is in this folder that the work library is pointed to. You could get the physical path by using the pathname('work') function. If you want to create a temp work space all you have to do is create a folder any where you want on your system and set a libname statement. At the end of you code you could run a
proc datasets kill lib=your_temp_libname;quit;
libname your_temp_libname; **to unregister the library;
and you have your temp library that acts like the work library.
I hope that this helps you Mike.
Klaz
 
Thanks Klaz,

If the 2nd temp lib resides under the work library path,
sas datasets stored in it would not be automaticlly deleted at the end of SAS session.

eg. under MS-windows OS
%sysexec mkdir "%SYSFUNC(PATHNAME(WORK))\tmp2";
libname WORK2 "%SYSFUNC(PATHNAME(WORK))\tmp2";

It acts like the permament library path. Its dataset needs the hard code to delete the datasets, such as
proc datasets kill lib=work2;

Idaelly, if the 2nd temp lib can be deleted automaticlly at endsas and just acts like WORK library or a temp fileref (such as FILENAME tmp1 temp;)?

Mike
 
Mike,
Why not write a small macro that does this job? Name it EndSas and execute it when your finished with your sas jobs (coding)

Here is an example:
In your config file (and every SAS session has one) you could write your setup code. Code that creates a work2 library wherever you choose.
like in you ex.
%sysexec mkdir "%SYSFUNC(PATHNAME(WORK))\tmp2";
libname WORK2 "%SYSFUNC(PATHNAME(WORK))\tmp2";

Then you do what you have to do and when your finished....

You execute this.

%EndSas(lib=your_lib);
proc datasets lib=&lib kill;
quit;
libname &lib; %* resets the libref;
endsas;
%mend EndSas;

%EndSas;

Would this do the trick that you want?
Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top