DATA Step, Macro, Functions and more

transfer the dataset to memory

Accepted Solution Solved
Reply
Contributor
Posts: 48
Accepted Solution

transfer the dataset to memory

hi,

 

  i am wondering how to transfer the dataset to memory, now i have a dataset in sas library, i am expected to transfer it to memory,  it is my professer's suggestion, and i never try to do it before. 

 

i knew that the stata operated in the memory. i have no idea about sas.

 

the 'memory'  just is the thing displayed in the windows task manager.

 

thank you!


Accepted Solutions
Solution
‎02-15-2017 03:35 AM
Trusted Advisor
Posts: 1,018

Re: transfer the dataset to memory

There's no point in transferring a data set to memory unless you plan to access it multiple times within your sas program.  After all it has to be read from disk at least once.

 

But there is a way to load into memory.  Take a look at documentation of the sasfile statement sasfile statement.  It includes an example of "using sasfile in a program with multiple steps".

 

However, be aware of limitations.  There are limited ways to modify the contens of a dataset loaded into memory via the sasfile statement.  The table below has a list of limitations:

 

Processing Requests for a File Opened by SASFILE
Processing Request
Open Mode
Allowed
APPEND procedure
update
Yes
DATA step that creates or replaces the file
output
No
DATASETS procedure to rename or add a variable, add or change a label, or add or remove integrity constraints or indexes
utility
No
DATASETS procedure with AGE, CHANGE, or DELETE statements
does not open the file but requires exclusive access
No
FSEDIT procedure
update
Yes
PRINT procedure
input
Yes
SORT procedure that replaces original data set with sorted one
output
No
SQL procedure to modify, add, or delete observations
update
Yes
SQL procedure with CREATE TABLE or CREATE VIEW statement
output
No
SQL procedure to create or remove integrity constraints or indexes
utility
No
 

 

 

View solution in original post


All Replies
Solution
‎02-15-2017 03:35 AM
Trusted Advisor
Posts: 1,018

Re: transfer the dataset to memory

There's no point in transferring a data set to memory unless you plan to access it multiple times within your sas program.  After all it has to be read from disk at least once.

 

But there is a way to load into memory.  Take a look at documentation of the sasfile statement sasfile statement.  It includes an example of "using sasfile in a program with multiple steps".

 

However, be aware of limitations.  There are limited ways to modify the contens of a dataset loaded into memory via the sasfile statement.  The table below has a list of limitations:

 

Processing Requests for a File Opened by SASFILE
Processing Request
Open Mode
Allowed
APPEND procedure
update
Yes
DATA step that creates or replaces the file
output
No
DATASETS procedure to rename or add a variable, add or change a label, or add or remove integrity constraints or indexes
utility
No
DATASETS procedure with AGE, CHANGE, or DELETE statements
does not open the file but requires exclusive access
No
FSEDIT procedure
update
Yes
PRINT procedure
input
Yes
SORT procedure that replaces original data set with sorted one
output
No
SQL procedure to modify, add, or delete observations
update
Yes
SQL procedure with CREATE TABLE or CREATE VIEW statement
output
No
SQL procedure to create or remove integrity constraints or indexes
utility
No
 

 

 

Super User
Posts: 19,768

Re: transfer the dataset to memory

I'm guessing you likely mean you want to permanently save the dataset so you don't have to reimport it rather than actually save it to 'memory' which would usually be understood to be RAM. 

 

You can do this by first assigning a permanent library and then copying the file to that location.

 

libname MEM '/folders/myfolders/perm';

data mem.class;
set sashelp.class;
run;

Remember, that to access the data in the future you'll need to re-assign the library if you haven't set it to be assigned automatically at start up. 

Contributor
Posts: 48

Re: transfer the dataset to memory

thanks! as i knew little about the 'memory',actually, it is the RAM which you have mentioned above.

and i try the code like:

 

%let dsets = a ;
libname TEMP 'C:\Windows\TEMP' ACCESS=TEMP;
data temp.TEST_ML;
set &dsets;
run;

 

sorry for another question,is the TEMP  'cache' for sas?  someone has told me that delete the 'temp' folder when you finished your work. i did not know the reson. 

 

thank you!

Super User
Posts: 19,768

Re: transfer the dataset to memory

Temp in this case is a library and the data is not deleted. Typically SAS datasets without a two level name (ie no libname) are stored in the WORK library. Anything in the work library is erased when you end your SAS session. 

 

If you are trying to work in RAM, my first answer/code is incorrect. 

 

If you're trying to work in memory, maybe you should explain what you want to do in memory. Is it a lookup, merge, sort? 

I'm assuming this is an attempt to improve performance? 

 

Contributor
Posts: 48

Re: transfer the dataset to memory

yeah, i want to improve the performance. and use the ram, sorry i called it 'memory'.

 

i think the path TEMP 'C:\Windows\TEMP'  (which used to set up the 'temp' to use the RAM)

 

as 'C:\Windows\TEMP' this folder  already  exists there, maybe made automatically by sas. i am wondering if  this folder can be used to transfer the dataset to ram. or i should set up a new folder named 'temp' in 'c'   and change the path like'c:\temp'.

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 225 views
  • 0 likes
  • 3 in conversation