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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

 

ballardw
Super User

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.

Neeta
Fluorite | Level 6

Thank you!

rogerjdeangelis
Barite | Level 11
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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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