02-20-2017 03:05 PM
I'm having a problem, I'm developing a "SQL PROC" and it has a String field, I need to fill in this field with blanks at the end of the field.
Does anyone have a solution for this case?
Thank you in advance.
02-20-2017 04:06 PM
SAS variables of type Character are by "default" filled up with blanks.
What's the problem you're having? A newly created character variable not being long enough, or not printing with all the blanks, or....?
02-20-2017 04:13 PM
02-20-2017 04:31 PM
a field has a content that in the end needs to fill in empty spaces
That's something you don't need to do. A SAS character variable has a fixed length and gets always filled up with blanks at the end up to the defined length of this variable. It then also occupies memory and disk space for the full length - that's why with large character variables where you only save short strings in average option "compress=yes" will save you disk space.
If you create a new variable in a data step or a proc sql then use a LENGTH statement to define the variable. If you omit the LENGTH statement then SAS will define the variable implicitely with a length which is equal to the length of the string assigned.
proc sql; create table test as select "00001-test" as myVar_1 length=20, "00001-test" as myVar_2 from sashelp.class(obs=1) ; quit; proc contents data=test; run;
02-20-2017 04:54 PM
02-20-2017 05:00 PM - edited 02-20-2017 05:07 PM
I did the test and still the field does not fill in the blanks at the end, however every time I mouse in the field it says that the field size is equal to 49
That's what I'm trying to tell you:
The actual variable is "filled up with blanks" to the end of the length of the variable. That doesn't mean it always prints this way ("print" refers to any way you can look at it).
You must actually be aware of this "filled-up" state i.e. when you concatenate variables.
result=myvar1||myvar2; is different from result=trim(myvar1)||myvar2;
data test; length result $20 myVar1 myVar2 $10; myVar1='A'; myvar2='B'; result=myvar1||myvar2; output; result=trim(myvar1)||myvar2; output; run; proc print data=test; run;
my my Obs result Var1 Var2 1 A B A B 2 AB A B