BookmarkSubscribeRSS Feed
Jan_Schebeko
Calcite | Level 5

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

8 REPLIES 8
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
ballardw
Super User

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.

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
MikeZdeb
Rhodochrosite | Level 12

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

FGao
Calcite | Level 5

It works! Thank you for sharing! 

Tom
Super User Tom
Super User

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.

PaigeMiller
Diamond | Level 26

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)?

--
Paige Miller
Jan_Schebeko
Calcite | Level 5

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.

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
  • 8 replies
  • 5458 views
  • 1 like
  • 6 in conversation