BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have created a format using proc format. I applied the format to a variable in the data set. But the resultant data set is not displaying the entire contents of the field. It is truncating the value of the variable.
It is displaying only 10 characters in the field. proc format;
value $f_name
'Apple' = 'A'
'Banana' = 'B'
'grapes' = 'G'
'Mango' = 'M'
run;
data Fruit_frmt;
set sorted_Fruit;
format Fruit $f_name.;
run;

In the variable fruit where ever it does not have match in the proc format, it is truncating the display to 10 charecters. The field length of fruit is 50.
Please advise.
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Share whatever SAS code you are using to display the variable. It will help a lot with determining the source of your situation.

Scott Barry
SBBWorks, Inc.
Flip
Fluorite | Level 6
If you do not use an attribute or length statement the new character variable will be set to the length of the first value encountered.
Patrick
Opal | Level 21
Hmmm! Even an attrib statement doesn't help.
I would have stepped into this trap as well.

Any suggestion how to get the "other" cases like "Passionfruit" in the output variable?


proc format;
value $f_name default= 40 max=40 min=40
"Apple" = "A"
"Banana" = "B"
"Grapes" = "G"
"Mango" = "M"
;
run;

data have;
length fruit $ 50;
fruit='Apple';
fruit2=fruit;
output;
fruit='Passionfruit';
fruit2=fruit;
output;
run;

data Fruit_frmt;
set have;
format fruit2 $f_name.;
attrib fruit3 length=$50.;
fruit3=put(fruit,$f_name.);
run;

proc print data=Fruit_frmt;
run;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
When using the format-name in a FORMAT statement (or PUT function), specify a width attribute, as in $F_NAME50. to avoid the truncation.

Scott Barry
SBBWorks, Inc. Message was edited by: sbb
ArtC
Rhodochrosite | Level 12
When you specify the width on the format, be sure to specify it when the variable is created. In your case the FORMAT statement would need to come before the SET statement. The LENGTH statement would also do the trick.
[pre]data Fruit_frmt;
format Fruit $f_name50.;
*length fruit $50;
set sorted_Fruit;
run; [/pre]

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 1667 views
  • 0 likes
  • 5 in conversation