Your SAS programs, embedded in web apps and elsewhere

Saving workspace like R

Reply
Occasional Contributor
Posts: 6

Saving workspace like R

Hi,

I am a new user in SAS. I have shifted from R. I am dealing with a large data (hospitalization).

Everyday I open SAS, I loose a  lot of time to run all the previous codes to get the formatted and structured data for further use.

In R I used to save workspace and thus everyday when I start I could get back the latest works of previous day.

Is it possible here with SAS to save workspace given that I have SAS Base and Enterpirse Guide?

Dipanjan

PROC Star
Posts: 7,468

Saving workspace like R

If you save your files in a permanent directory (e.g., use a libname statement to define a library like:

  libname mydata "c:\current_data";

then, in your code, rather than just creating the files in your work directory (i.e., using something like:

data step1;

*whatever;

run;

Create them as permanent files.  e.g.:

data mydata.step1;

*whatever;

run;

Then, the next day, you just have to run the one line:  libname mydata "c:\current_data";

and all of your files will be accessible

Super User
Posts: 5,498

Saving workspace like R

Dinpanjan,

SAS supports a neat trick that lets you save the WORK area with minimal changes to your SAS program.  These changes have to be implemented at the beginning of your program, before adding to the WORK area.

As Art mentioned, you have to pre-define a folder where the WORK area will reside, using a LIBNAME statement.  From that point, however, you don't need to change the subsequent DATA and PROC steps.  Instead, add this line to the program (assuming the LIBNAME statement defined "mydata"):

options user=mydata;

The default option is user=WORK.  That's why your one-level data set names get stored in the WORK library.

Here's the part I'm not sure about.  If you want to re-use the same WORK area in a subsequent program, is it as simple as adding the same two lines to the subsequent program?  I suspect it is, but I'm not positive about that.

Of course, Art's method will give you better control if you wish to save just part of the WORK area and discard the rest.

Good luck.

Occasional Contributor
Posts: 6

Re: Saving workspace like R

Thanks a lot Art297 & Astounding.

I have applied method of Art297. While reopening, it was not throwing the data and may be that was because of more complication of the program.e.g.

data work.a;

set permanent.b;

/*subsetting*/

run;

data permanent.final;

set work.a;

/* formatting, restructuring, reformating, count */

run;

So can anybody help me to understand why I cannot retrieve my saved data in permanent library, even though I gave the path for the libref next day ?

Astounding,

What you were suspicious I tried. It works even when model output is needed to retrieve but in my purpose regarding several times formatting, restructuring, SQL joins etc, it is not working. So till now what way I have is to export all to csv at the end of the day and import on the next day. U know it causes loss of information that are capable with SAS data.

New Contributor
Posts: 4

Saving workspace like R

This post from Angela Hall might help.

Ask a Question
Discussion stats
  • 4 replies
  • 569 views
  • 6 likes
  • 4 in conversation