Help using Base SAS procedures

Applying a format-Not displaying the entire value for the variable

Reply
N/A
Posts: 0

Applying a format-Not displaying the entire value for the variable

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.
Super Contributor
Super Contributor
Posts: 3,174

Re: Applying a format-Not displaying the entire value for the variable

Posted in reply to deleted_user
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.
Super Contributor
Posts: 359

Re: Applying a format-Not displaying the entire value for the variable

Posted in reply to deleted_user
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.
Respected Advisor
Posts: 4,173

Re: Applying a format-Not displaying the entire value for the variable

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;
Super Contributor
Super Contributor
Posts: 3,174

Re: Applying a format-Not displaying the entire value for the variable

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
Valued Guide
Posts: 634

Re: Applying a format-Not displaying the entire value for the variable

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]
Ask a Question
Discussion stats
  • 5 replies
  • 208 views
  • 0 likes
  • 5 in conversation