BookmarkSubscribeRSS Feed
xxformat_com
Barite | Level 11

Hi,

 

The length field (LENGTH in the format catalog) is the actual maximal length in the format LABEL.

Question: is there any place where this information is used by the SAS system e.g. checking some information, used by an option...

for me.

What was the intention when it was decide to store the information in the format catalog?

I can find explaination with the min, max and default length but not with the actual maximal length.

I can only imagine extracting the format catalog in a dataset and use this information in a classical manner. But there a lengthn function would likely be sufficient

 

proc format;
   value ny (default=7) 0='No'
                        1='Yes';
run;

proc format fmtlib;
run;

 

6 REPLIES 6
Tom
Super User Tom
Super User

I don't really know what LENGTH is used for.  MIN, MAX and DEFAULT are the key attributes.  DEFAULT says what width to use if the format specification does not include a width.  MIN and MAX sets the range of values you can use as the width.

 

Experiment and see.

proc format;
   value ny 
  0='No'
  1='Yes'
  2='Padded '
;
run;

proc format cntlout=formats;
run;

proc print data=formats;
  var fmtname start length min max default label;
run;

Basically the LENGTH seems to be set to the maximum length for any label value.  If you don't overwide the DEFAULT length then that will be set to the same thing.  It does not appear to make any attempt to figure out how to set MIN and MAX.

 

 

xxformat_com
Barite | Level 11
I have the same conclusions as you. I can explain DEFAULT, MIN, MAX too. Not an issue but what I don't know where LENGTH is used for and what was the intention having it in the catalog. My test also when in the direction LENGTH that is the maximal observed/actual length.
ballardw
Super User

Generally what I run into with custom formats and default length if not supplied in the format definition is that the default display for "long" text gets truncated with the internal default length.

 

One place that the default may cause unexpected results is when concatenating formatted values when using the || operator or some of the string functions. You may find leading spaces in numeric values displaying formatted values because numeric results will default to right justification in most uses.

 

The Max comes into play when someone attempts, whether intentionally or not, to use a very large value for the Width of a format.

Suppose you accidentally type something like:   Format somevar ny2000. ; That is not a syntax error and if your format does not have MAX value less than 2000 SAS will attempt to display Somevar using 2000 characters. Which would be overkill for "yes" or "no". So the default Max of 40 limits the result actually displayed.

Reeza
Super User
It won't affect numeric much, try playing around with some character formats instead and modifying the length of the created formatted value and the length of the input variable.
FreelanceReinh
Jade | Level 19

@xxformat_com wrote:

But there a lengthn function would likely be sufficient


Not in cases where other formats are specified as labels (as in Example 4 of the VALUE statement documentation). Then the explicit length specifications of those formats (if any) are taken into account when the length of the new format is determined.

xxformat_com
Barite | Level 11

You're right I didn't think of that scenario. The lengthn function would not work there.

I just add an example for future reader of this post.

 

proc format;
   value ny (default=7) 0='No'
                        1='Yes';
   value nybis .=' '
               other=[demo10.];
run;

proc format fmtlib;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 398 views
  • 1 like
  • 5 in conversation