BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mike_B
Obsidian | Level 7

I thought I understood how the memtype option in proc datasets worked, but I guess I was wrong. My program creates lots of temporary datasets as well as some formats and macros. I need to delete most--but not all--of the datasets after each iteration of a particular macro, but I need to save some sets and all formats and macros. I thought memtype=data would exclude macros and formats from deletion, but the formats are still getting deleted. What am I doing wrong?

 

proc datasets lib=work nolist;
	save c final: template: / memtype=data; *these are all data sets;
quit;

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
AMSAS
SAS Super FREQ

@Mike_B Here's a simple example that explains what is happening 

See bullet #2 In Subordinate Statements:

after a slash (/) at the end of the statement. When used following a slash, the MEMTYPE= option refers to all SAS files named in the statement unless the option appears in parentheses after the name of a SAS file. For example, the following statement deletes Lotpix.catalog, Regions.data, and Appl.catalog:

delete lotpix regions(memtype=data) appl / memtype=catalog;

 

i.e. MEMTYPE applies to the datasets you have listed in the SAVE statement 

 

In the example below, I create a formats catalog and a formats dataset, when the PROC DATASETS executes it will delete the formats catalog as the MEMTYP=DATA tells it only to save the FORMATS dataset

Hope this helps

 

 

proc format ;
	value
		$sex "M"="Male" "F"="Female" ;
run ;

data work.test1 ;
	do i=1 to 5 ;
		output ;
	end ;
run ;

data work.test2 ;
	do i=1 to 5 ;
		output ;
	end ;
run ;

data work.formats ;
	do i=1 to 5 ;
		output ;
	end ;
run ;

proc datasets lib=work nolist ;	
	save test2  formats / memtype=data; /* memtype only applies to the list of datasets in the SAVe statement */
	                                    /* i.e. the formats dataset is not deleted but the formats catalog is */
quit;

 

 

View solution in original post

2 REPLIES 2
AMSAS
SAS Super FREQ

@Mike_B Here's a simple example that explains what is happening 

See bullet #2 In Subordinate Statements:

after a slash (/) at the end of the statement. When used following a slash, the MEMTYPE= option refers to all SAS files named in the statement unless the option appears in parentheses after the name of a SAS file. For example, the following statement deletes Lotpix.catalog, Regions.data, and Appl.catalog:

delete lotpix regions(memtype=data) appl / memtype=catalog;

 

i.e. MEMTYPE applies to the datasets you have listed in the SAVE statement 

 

In the example below, I create a formats catalog and a formats dataset, when the PROC DATASETS executes it will delete the formats catalog as the MEMTYP=DATA tells it only to save the FORMATS dataset

Hope this helps

 

 

proc format ;
	value
		$sex "M"="Male" "F"="Female" ;
run ;

data work.test1 ;
	do i=1 to 5 ;
		output ;
	end ;
run ;

data work.test2 ;
	do i=1 to 5 ;
		output ;
	end ;
run ;

data work.formats ;
	do i=1 to 5 ;
		output ;
	end ;
run ;

proc datasets lib=work nolist ;	
	save test2  formats / memtype=data; /* memtype only applies to the list of datasets in the SAVe statement */
	                                    /* i.e. the formats dataset is not deleted but the formats catalog is */
quit;

 

 

Mike_B
Obsidian | Level 7

Thank you. I modified (below), and it now saves the format catalog as well as the data files.

proc datasets lib=work nolist memtype=(data catalog);
  save c final: template: formats;
quit;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2133 views
  • 3 likes
  • 2 in conversation