DATA Step, Macro, Functions and more

Copy a format

Reply
New Contributor
Posts: 2

Copy a format

Hi,

i'm a novice on SAS Formats.

 

I want to copy a format to a backup one.

 

something like formata = formatb;

 

I didnt find it on google. Only one i found was to copy inside a catalog. But i didn't know the catalog name of the format.

 

Is there any easy way? please help.

 

Thx Jan

Trusted Advisor
Posts: 1,933

Re: Copy a format

[ Edited ]
Posted in reply to Jan_Schebeko

I'm not really sure I understand the concept of copying a format to a backup.

 

But if I do understand this, here is the method I use

 

I create permanent formats, and then store them on a drive that is automatically backed up.

 

So, for example

 

libname fmtlib "\\myserver\mydrive\myfolder";
proc format library=fmtlib;
value yn 0='No' 1='Yes';
run;

Then the commands

 

libname fmtlib "\\myserver\mydrive\myfolder";
options fmtsearch=(fmtlib);

allows the formats in fmtlib (all of them if there are more than one, not just the one format I named YN) to be available to be used in your SAS program.

Super User
Posts: 11,343

Re: Copy a format

Posted in reply to Jan_Schebeko

I've never had a need to do this but if you are using base SAS and don't need to do this for a lot of formats you can open the format catalog in the library of interes using the SAS explorer window and copy/paste.

 

Since there isn't much a way to edit a format within a catalog I almost have to believe that you are "experimenting" with creating a variation on the existing format. In which case you might be better off to make sure you have the source code saved somewhere safe to recreate the format as needed.

Or put the new formata into a different library and have that library appear first in the FMTSEARCH path.

Trusted Advisor
Posts: 1,933

Re: Copy a format


ballardw wrote:

I've never had a need to do this but if you are using base SAS and don't need to do this for a lot of formats you can open the format catalog in the library of interes using the SAS explorer window and copy/paste.

 

Since there isn't much a way to edit a format within a catalog I almost have to believe that you are "experimenting" with creating a variation on the existing format. In which case you might be better off to make sure you have the source code saved somewhere safe to recreate the format as needed.

Or put the new formata into a different library and have that library appear first in the FMTSEARCH path.


Yes, if I am creating a permanent format, I always save the source code.

Valued Guide
Posts: 765

Re: Copy a format

[ Edited ]
Posted in reply to Jan_Schebeko

Hi.  Formats are stored in CATALOGS. Numeric formats have an ENTRYTYPE (ET) of FORMAT, while character formats are FORMATC.  Here's an example that makes a few formats, copies two of them to a different catalog, then displays the contents of the two format catalogs ...

 

libname x 'z:\';

 

proc format lib=z.formats;
value abc
1 = 'one'
2 = 'two'
;
value $abc
'one' = '1'
'two' = '2'
;
value notcopied
1 = '99'
2 = '88'
;
run;

 

libname y 'e:\';

proc catalog cat=z.formats;
copy out=y.formats;
select abc / et=format;
select abc / et=formatc;
run;
quit;

 

proc catalog cat=z.formats;
contents;
run;
quit;

 

proc catalog cat=y.formats;
contents;
run;
quit;


                             Contents of Catalog Z.FORMATS

#    Name         Type               Create Date          Modified Date
1    ABC          FORMAT     10/20/2015 12:31:46    10/20/2015 12:31:46
2    NOTCOPIED    FORMAT     10/20/2015 12:31:46    10/20/2015 12:31:46
3    ABC          FORMATC    10/20/2015 12:31:46    10/20/2015 12:31:46

 

                          Contents of Catalog Y.FORMATS

#    Name    Type               Create Date          Modified Date
1    ABC     FORMAT     10/20/2015 12:31:46    10/20/2015 12:31:46
2    ABC     FORMATC    10/20/2015 12:31:46    10/20/2015 12:31:46

Super User
Super User
Posts: 7,078

Re: Copy a format

Posted in reply to Jan_Schebeko

You can use PROC CATALOG to manipulate existing formats. There does not appear to be a command to copy an entry to a new name in the same catalog.  I would suggest copying it to dummy catalog in the WORK library, using the CHANGE command to rename it and then copy it back.

 

Or you could just use PROC FORMAT with the CNTLOUT= option to output the definition to a data set, edit the FMTNAME variable in the dataset and then use PROC FORMAT with the CNTLIN= option to define the new format.  Not sure if this will work for picture or other more complex formats.

Trusted Advisor
Posts: 1,933

Re: Copy a format

[ Edited ]

I'm still curious (as I was at the beginning of this thread) why anyone would want to make a copy of a format and store it somewhere else. WIth the code I provided, a user only needs one such catalog with a format, and this can be used in every program that the user writes; and if it is on a shared disk, then every user with access to the shared disk can use this format.

 

Now, here at my company (and I'm quite sure at all companies), the files (including this catalog) are backed up regularly, why would you need multiple copies of a format (other than the automatic backup)?

New Contributor
Posts: 2

Re: Copy a format

Posted in reply to PaigeMiller

The problem was that the format is overwritten on using the macro that generate it, more the one times. So anyway... I have solve this simple, by find out to write the results that contains a column where not the  value with formats is sorted, then the value of the format is stored and can be printed on the end. Thanks for take part on this request.

Ask a Question
Discussion stats
  • 7 replies
  • 809 views
  • 1 like
  • 5 in conversation