DATA Step, Macro, Functions and more

Can we name user-defined names to user-defined formats?

Accepted Solution Solved
Reply
Contributor
Posts: 65
Accepted Solution

Can we name user-defined names to user-defined formats?

Below is a program to create some user-defined formats and to store them in myfmts library:

 

libname myfmts '/folders/myfolders/formats';
libname learn '/folders/myfolders';

proc format library=myfmts;
	value $gender 'M'='Male' 'F'='Female' ' '='Not entered' other='Miscoded';
	value age low-29='Less than 30' 30-50='30 to 50' 51-high='51+';
	value $likert '1'='Strongly disagree' '2'='Disagree' '3'='No opinion' 
		'4'='Agree' '5'='Strongly agree';
run;


proc format library=myfmts;
	value agenew low-<10 = 'Less Than 10' 10-<20 = '10-20' 20-<30 = '20-30'
			30-<40 = '30-40' 40-<50 = '40-50' 50-high = 'Greater Than 50';
run;

Now, all formats are getting stored in same file viz. "formats.sas7bcat".

Can I,

1. Change the name of this file to say, age_fmts etc. while programming.

2. Here, I am using proc format procedure two times, generally I want to save two (format) files in my library myfmts (or to my folder "formats"). But, I am getting only one file viz. formats.sas7bcat instead of two.  However, I can see that all of my formats are get saved in same file (formats.sas7bcat) by running: proc format library=myfmts fmtlib; run; commands.  But, can I generate two files in same folder "formats" and can I decide there names also.
 

Regards,
AG_Stats

Accepted Solutions
Solution
‎06-02-2016 07:46 AM
Super User
Super User
Posts: 7,942

Re: Can we name user-defined names to user-defined formats?

Formats are stored in a SAS catalog, called formats.sas7bcat.  You can have diffrerent files in differrent location, but not two in one place (as far as I can remember).  If you need to do this, then why not create a dataste of your formats - you can have as many of them as you want and call it what you want.  Or, a better solution to my mind, avoid proprietary file formats all together, if you really have to use formats (and I never do anymore), then save as text file and run each time, or use datasets.  

View solution in original post


All Replies
Solution
‎06-02-2016 07:46 AM
Super User
Super User
Posts: 7,942

Re: Can we name user-defined names to user-defined formats?

Formats are stored in a SAS catalog, called formats.sas7bcat.  You can have diffrerent files in differrent location, but not two in one place (as far as I can remember).  If you need to do this, then why not create a dataste of your formats - you can have as many of them as you want and call it what you want.  Or, a better solution to my mind, avoid proprietary file formats all together, if you really have to use formats (and I never do anymore), then save as text file and run each time, or use datasets.  

Contributor
Posts: 65

Re: Can we name user-defined names to user-defined formats?

Thanks RW9. However, I only know to make dataset for character formats (and somewhat for numeric).  Can you give me an example of dataset (or raw text file) having formats for group of ranges.  For this please give me the codes, use the following formats:

 

proc format library=myfmts;
	value $gender 'M'='Male' 'F'='Female' ' '='Not entered' other='Miscoded';
	value age low-29='Less than 30' 30-50='30 to 50' 51-high='51+';
	value $likert '1'='Strongly disagree' '2'='Disagree' '3'='No opinion' 
		'4'='Agree' '5'='Strongly agree';
        value $likert_new '1'-'3' = 'Agree' '4','5' = 'Disagree';
run;

Thanks in Advance,

Regards,
AG_Stats
Super User
Super User
Posts: 7,942

Re: Can we name user-defined names to user-defined formats?

You have provided it.  Just save that code to a text file, then #include it in any program thats needs it.

Super User
Posts: 7,762

Re: Can we name user-defined names to user-defined formats?

If you use a two-level name in the library= part of the proc format statement, you can name the catalog in addition to the library.

You must then specify that catalog in the fmtsearch system option.

proc format library=mylib.myfmts ........

options fmtsearch=(mylib.myfmts);
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 5,424

Re: Can we name user-defined names to user-defined formats?

There's usually no pint in have different format catalogs, or have them renamed.

The formats itself become "entries" within that catalog, with the same name as the format as specified in PROC FORMAT, with the entry type as FORMAT (nume) or FORMATC (char).

You can browse the contents of the SAS format catalog (file) by using PROC CATALOG.

Data never sleeps
Super User
Posts: 11,343

Re: Can we name user-defined names to user-defined formats?

There is another very good reason not to separate out the formats into a separate catalog per format. The SAS option that tells where to look for formats, FMTSEARCH, will, when given a library to search for formats, find all of them if they are in a default named FORMATS catalog. Otherwise you would have to specific each and every separate catalog by name for it to be found.

 

☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 365 views
  • 4 likes
  • 5 in conversation