Need to fill whitespaces in SAS variable

saswhitespace

Slightly stunned here.

I have a SAS variable that has values of varying lengths.

If the memory required for the variable is below a threshold(48bytes), I have the append white spaces to the variable so that it reaches that memory allocation.

How would I do this in SAS?

More importantly, where can I find documentation regarding the memory taken up by a single white space(or any other character/type) in SAS?

Edit:
stevepastelan's answer was perfect actually 🙂

Best Answer

Character variables in SAS are automatically padded to the right to fill their length, however, certain statements, such as the PUT statement, may trim them when displaying.

You can use formats to force the output, ex:

data test;
    length x $ 8;    

    x = "XX";   
    put "1) " x     "END"; /* Omitting the format will trim the printed variable value */    
    put "2) " x $8. "END"; /* Now it's shown as right-padded */


    x = "123456789";       /* The extra character is truncated from the variable */
    put "3) " x $8. "END";             
    put "4) " x $9. "END"; /* increasing format width will add extra right padding */
    put "5) " x $6. "END"; /* A shorter format will truncate the display */
run; 

Writes the following to the SAS log:

1) XX END
2) XX      END
3) 12345678END
4) 12345678 END
5) 123456END
Related Topic