BookmarkSubscribeRSS Feed
RoddyJ
Obsidian | Level 7

Hi everyone,

 

I'm using a format created with the below code:

proc format cntlin=neonate_formats;
run;

To format a character variable from a character code to a name. Some the resulting variable isn't the correct length so some of the rows have the name cut off.

I've put in a length statement in the datastep and that hasn't helped, I can't think what else to do. I'm not sure if the fault is in the format (checked the dataset used to create the format and that's as expected). Can anyone help?

 

Datastep looks like below:

data formatted;
length team $100;
set unformatted;

team = put(uteam, $teamf.);

run;
2 REPLIES 2
Tom
Super User Tom
Super User

Changing the length of the target variable means there is room for longer strings.

To have the PUT function generate longer strings you should either tell it that in the format specification by including a width.

team = put(uteam, $teamf100.);

Or change the default width in the format definition.

FreelanceReinh
Jade | Level 19

Hi @RoddyJ,

 

I would check the default length of format $teamf.:

proc format fmtlib;
select $teamf;
run;

Output starts like this:

----------------------------------------------------------------------------
|       FORMAT NAME: $TEAMF   LENGTH:   20   NUMBER OF VALUES:    3        |
|   MIN LENGTH:   1  MAX LENGTH:  40  DEFAULT LENGTH:  12  FUZZ:        0  |

If the default length is smaller than the length (as shown above), truncation will occur for longer values (unless you specify a greater length in the PUT statement as suggested by Tom; this length is limited by the maximum length, 40 in the example). The default length might have been set inappropriately by a variable named default in dataset neonate_formats which has too small a value in the first observation for format $teamf..

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 791 views
  • 2 likes
  • 3 in conversation