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

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
1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.  

AG_Stats
Quartz | Level 8

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
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

Kurt_Bremser
Super User

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);
LinusH
Tourmaline | Level 20

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
ballardw
Super User

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.

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 1436 views
  • 4 likes
  • 5 in conversation