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
@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 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;
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.