Hi all,
I'm working on a program where I want to add a format to existing format catalog i.e. I see a format catalog myformats.sas7bcat but I dont know which program creates that catalog. As most of the programs in my project already use that catalog using fmtsearch option, I want to add my new format to the same catalog.
Thanks in advance!
If you want to add a format to a specific catalog then reference it the LIBRARY option in Proc Format.
proc format library=work.myformat; value y 1 = '10' other= 'something else'; ; run;
If the catalog does not exist the code will create the catalob myformat in the work library.
If the format Y does not exist in the catalog myformat in the Work library it will be added to the catalog.
If the format Y does exist in the catalog myformat in the Work library then, assuming no error, the new format Y replaces the old one.
So, you don't know where that is created, and that format catalog is used by other things. Are you sure you want to be updating it? I would really advise to find out more about what creates that, where, etc. as overwriting it may cause problems.
If you want to add a format to a specific catalog then reference it the LIBRARY option in Proc Format.
proc format library=work.myformat; value y 1 = '10' other= 'something else'; ; run;
If the catalog does not exist the code will create the catalob myformat in the work library.
If the format Y does not exist in the catalog myformat in the Work library it will be added to the catalog.
If the format Y does exist in the catalog myformat in the Work library then, assuming no error, the new format Y replaces the old one.
Thank you!
Copying individual prebuilt formats from one format catalog to another +goodies
inspired by
https://goo.gl/N24fhV
https://communities.sas.com/t5/Base-SAS-Programming/Adding-SAS-format-to-existing-catalog/m-p/341634
HAVE ( Two prebuilt formats in separate catalogs)
==================================================
Contents of Catalog WORK.CAT1ST
# Name Type
--------------------------
1 CAT1STFMT FORMATC
Contents of Catalog WORK.CAT2ND
# Name Type
---------------------------
1 CAT2NDFMT INFMT
WANT (both formats in catalog cat2nd)
======================================
Contents of Catalog WORK.CAT2ND
# Name Type
---------------------------
1 CAT1STFMT FORMATC
2 CAT2NDFMT INFMT
WORKING CODE
===========
copy in=work.cat1st out=work.cat2nd ;
select cat1stfmt/entrytype=formatc;
FULL SOLUTION
=============
* just in case the catalogs exist then delete them;
proc datasets library=work memtype=(catalog);
delete cat1st / memtype=catalog;
delete cat2nd / memtype=catalog;
run;
* create three catalogs and combine them;
proc format library=work.cat1st;
value $cat1stfmt
'F' = 'Female'
'M' = 'Male';
run;quit;
proc format library=work.cat2nd;
invalue cat2ndfmt
'F' = 1
'M' = 2;
run;quit;
*Copy cat1stfmt to catalog cat2nd;
proc catalog ;
copy in=work.cat1st out=work.cat2nd ;
select cat1stfmt/entrytype=formatc;
run;quit;
* _ _
__ _ ___ ___ __| (_) ___ ___
/ _` |/ _ \ / _ \ / _` | |/ _ \/ __|
| (_| | (_) | (_) | (_| | | __/\__ \
\__, |\___/ \___/ \__,_|_|\___||___/
|___/
;
* add discriptions;
proc catalog cat=work.cat2nd;
modify cat1stfmt.formatc (
description="m->male f->female");
modify cat2ndfmt.infmt (
description="m->2 f->1");
run;quit;
/*
NOTE: Copying entry CAT1STFMT.FORMATC from catalog WORK.CAT1ST to catalog WORK.CAT2ND.
*/
* verify descriptions;
proc catalog cat=work.cat2nd;
contents;
run;quit;
/*
# Name Type Description
--------------------------------------------
1 CAT1STFMT FORMATC m->male f->female
2 CAT2NDFMT INFMT m->2 f->1
*/
* liat all formats;
proc format fmtlib library=work.formats;
run;quit;
/* delete individual format entries */
proc catalog catalog=work.formats;
delete win2unx.formatc;
delete win2unx.format;
delete win2unx.infmt;
run;quit;
/* delete catalogs */
proc datasets library=work memtype=(catalog);
delete cat1st / memtype=catalog;
delete cat2nd / memtype=catalog;
delete cat3rd / memtype=catalog;
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.