DATA Step, Macro, Functions and more

Adding SAS format to existing catalog

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

Adding SAS format to existing catalog

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!


Accepted Solutions
Solution
‎03-16-2017 01:58 PM
Super User
Posts: 11,343

Re: Adding SAS format to existing catalog

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.

View solution in original post


All Replies
Super User
Super User
Posts: 7,988

Re: Adding SAS format to existing catalog

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.

 

Solution
‎03-16-2017 01:58 PM
Super User
Posts: 11,343

Re: Adding SAS format to existing catalog

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.

Occasional Contributor
Posts: 16

Re: Adding SAS format to existing catalog

Thank you!

Valued Guide
Posts: 505

Re: Adding SAS format to existing catalog

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;
☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 258 views
  • 0 likes
  • 4 in conversation