BookmarkSubscribeRSS Feed
novinosrin
Tourmaline | Level 20

Good morning folks,

I would like to use a dataset contents as formats using control options(CNTLIN/OUT), however I want to be absolutely sure of the lengths and names of format names that my dataset concatenated variables that would  go as FMTNAME. My concern is that I vaguely remember fmtnames in value/pic formats do not exceed 32 chars. I also vaguely remember the FMTNAME from a dataset doesn't quite have to conform to that rule??? I did a below test and it seems to be fine up to 40 chars, yet I want to confirm with you before I write the full code and move to production. 

 

I know you would quite likely ask whether have I read the docs, hmm not quite. I am being cheeky here as I am really not feeling well and am tired this morning and would like some help. Pardon me please!  Some confirmation from you folks will give me the confidence after all. That's my need!

 

PS Any additional caution, please please please let me know-



data fmt;
/*Assign a lengthy fmtname*/
 retain fmtname 'abcfkjjhgfkljsebnglwkjengkljwejnrwkjnjnrgvkjsnbvkjaesnbrkfbnabnvlseajbndlksjnvdasdbnsk';
 start=1;
 end=5;
 label='ok';
 output;
 start=.;
 end=.;
 label='NA';
 hlo='o';
 output;
run;

proc format cntlin=fmt fmtlib;
run;

data test;
 set fmt(keep=fmtname);
 do i=1 to 10;
  need=putn(i,fmtname);
  output;
 end;
 stop;
run;


 

The MAX LENGTH takes 40 chars. Can this be modified to accommodate higher lengths? 

 

 

3 REPLIES 3
Kurt_Bremser
Super User

When you look at the output of proc format. you will see that the name has been truncated.

So while you can use longer variables, everything after character 32 (or 31 for character formats) will have no effect, and such names might lead to funny results (inadvertently "concatenated" or replaced formats).

Reeza
Super User

Just out of curiousity, adding on to this question, do you need to leave spaces in the name for the width and decimal portion?

 

I know the format may not use that, but it's sort of an implicit parameter in any format if I understand correctly (which may not be right at all).

 

 

Tom
Super User Tom
Super User

I think you are confusing the name of the format (which is limited to 32 characters) and an actual format specification.  A format specification must include a period (so 33 characters) and can also include a width and decimal places numbers.  Since the maximum length SAS allows for character strings is 32,767 the maximum number of digits needed for the width is 5.  I suspect that the maximum number of digits that are allowed for decimal places is much smaller than 32,767.  I have normally seen people use a length of 41 for a variable that is used to store a format specification.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 520 views
  • 0 likes
  • 4 in conversation