3

we have a Enterprise Guide Project, where we have multiple process flows. Output of each process flow is saved to specific Library called "SAVE", defined with LIBNAME statement. This is done so that we could easier jump and work on any process flow without needing to run all above process flows (except of course the process flow which would initialize SAVE Library with LIBNAME statement).

However, when we want to run this code on PRODUCTION server, we would like that this SAVE Library points to SAS WORK Data Library, as we dont need this in-between data.

Is it possible to direct the Library to WORK Data Library, using LIBNAME Statement (e.g. "LIBNAME SAVE SAS.WORK;") ?

dsolimano
  • 8,870
  • 3
  • 48
  • 63
Sale
  • 349
  • 1
  • 3
  • 15

3 Answers3

4

The define a libref use the LIBNAME statement. To find the path used by an existing libref use the PATHNAME() function.

libname save %sysfunc(quote(%sysfunc(pathname(work)))) ;

Be careful using this trick because SAVE.memname and WORK.memname will now refer to the same physical file. Code that worked in your development environment might not work because of name conflicts.

Tom
  • 47,574
  • 2
  • 16
  • 29
  • 1
    It's simpler to just use double-quote literals than wrap the `quote()` function in a `%sysfunc()` call. This would then become: `libname save "%sysfunc(pathname(work))";`. – Robert Penridge Jun 26 '15 at 18:41
  • Hello Tom, Regarding your comment, so, as long as I take care the all datasets I name in WORK.* library does not collide with SAVE.* library, I should be fine. – Sale Jun 29 '15 at 09:01
  • Right. In your development environment where SAVE is a different place than WORK you could make dataset SAVE.X and it would be different than dataset WORK.X. If you then later reference WORK.X in your program the code might work differently because when you create SAVE.X you are over writing any existing WORK.X dataset. – Tom Jul 02 '15 at 18:02
  • The QUOTE() function might not be needed for a LIBNAME statement, but there are still many DOS commands that cannot handle unquoted paths with embedded spaces. So frequently macro variables that contain paths will include quotes. In those cases QUOTE() function call makes sure that the embedded quotes are properly doubled up. – Tom Jul 02 '15 at 23:03
3

Ok, I found a way to do it.

%let workLocation=%sysfunc(getoption(work));
libname SAVE "&workLocation.";

There is even simpler solution:

libname SAVE (work);
Sale
  • 349
  • 1
  • 3
  • 15
1

One thing you can do is reassign the WORK library so it points where your SAVE library is.

Here, in point 1, they explain how to do it: https://riskopedia.wordpress.com/2007/03/06/reassign-location-on-sas-work-folder/

  • 1
    True that is cool idea, that way we delegate to SAS to take care (delete) whatever was stored in the end on SAVE libref. Only thing is that then we would need to define some temp folder where this could be saved, thus we would create additional (garbage) folder on Production server, which is for this particular case no-go. – Sale Jun 25 '15 at 13:23