BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
YasodaJayaweera
Obsidian | Level 7

I have created a custom numeric format below. However, the format is not applied to the data. I can't understand the reason. Can you please have a look?

Please note that the code was executed in SAS On Demand.

 

libname myformat '/home/u48733392/Chapter11';
proc format library=myformat;
   value tiers  20000-49999  = 'Tier 1'                  
                50000-99999  = 'Tier 2'
               100000-250000 = 'Tier 3';
run;

data myData;
   input First $ Salary;
   datalines;
Stacey 20000
Mary 30000
George 52256
Gloria 99999.87
Kammy 156906
James 250000
;
proc print data=myData;
run;

proc print data=myData;
	var First Salary;
	format Salary tiers.;
run;

 Below is the output of the code:outputoutput

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
japelin
Rhodochrosite | Level 12

Use fmtsearch first.

options fmtsearch=(myformat);

View solution in original post

6 REPLIES 6
Reeza
Super User

Works fine for me. 

Gloria's falls out because the previous format ends at 99,999 and the next one starts at 100,000 leaving the decimal fraction unaccounted for. 

 

You may want to define it as follows instead:

 

 

proc format;
   value tiers  20000-<50000  = 'Tier 1'                  
                50000-<100000  = 'Tier 2'
               100000-250000 = 'Tier 3';
run;

EDIT: my mistake, you created the format in a library so you also need to tell SAS which library to use to find the format. @japelin has provided that code. 

Then you can fix the other issue with the suggested code above. 

YasodaJayaweera
Obsidian | Level 7
Thank you for the explanation. @japelin I got it now.
japelin
Rhodochrosite | Level 12

Use fmtsearch first.

options fmtsearch=(myformat);
YasodaJayaweera
Obsidian | Level 7

Thank you for the quick reply. The code worked. I am preparing for the SAS base programmer exam and fmtsearch option is not mentioned in the prep guide. Can you pleas elet me know what is the exact use of 'fmtsearch'? Why wouldn't code work without it? 

japelin
Rhodochrosite | Level 12

Format is searched in work library and library library in default.
fmtsearch can add specific library to search.

 

If you want more detail, please read document.

 

ballardw
Super User

@YasodaJayaweera wrote:

Thank you for the quick reply. The code worked. I am preparing for the SAS base programmer exam and fmtsearch option is not mentioned in the prep guide. Can you pleas elet me know what is the exact use of 'fmtsearch'? Why wouldn't code work without it? 


FMTSEARCH is a SAS environment setting for where to search for Formats.

If you place a format in a library other than WORK or the SAS supplied locations then you need to tell SAS where to look to find your format.

Your code:

proc format library=myformat;

specified a different library. If you had not provided the Library option the default would be to place the format in the WORK library and nothing needed.

 

You may actually want to APPEND your library to the FMTSEARCH path such as

options append=(fmtsearch=myformat);

to add the library to the end of the list of locations SAS searches (or Insert to make it the first location to search).

SAS searches for a specified format in the locations in order of appearance. If you use "options fmtsearch=myformat". The Work library will no longer be searched.

You can see your current setting for the option using:

proc options option=fmtsearch;
run;

For example on the computer I am working with that shows this in the log:

FMTSEARCH=(WORK LIBRARY CENT)
                   Specifies the order in which format catalogs are searched.

So when I use a format such as Somefmtname. SAS will first look in the Work library for the format, if not found then in LIBRARY (the SAS supplied formats) and then last in the CENT library.

Note that order can be important if you happen to have multiple formats of the same name.

 

I not-infrequently will want to temporarily modify a format to test something. So placing the test version in the WORK library will not disturb the one in the permanent library (Cent in this case) but will use the same name in the Work library as it is found there first.

 

In another environment I have 9 additional permanent libraries with formats for specific recurring projects. The FMTSEARCH option lets be specify all of them without having to try to rerun code or such.

 

Note that you can specify a Catalog name for the formats as well as the library. If you do such then you need to make sure the catalog is included in the FMTSEARCH list.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 634 views
  • 4 likes
  • 4 in conversation