0
votes

I have a SAS dataset with a field title Name containing character values with length up to 50. If the number of characters is less than 50, I would like to add trailing spaces to the existing string such that the full length is made to be 50 characters.

I have tried length, format, and put statements without success.

2
Can you please post what you are trying to do? SAS character fields are always fixed length and padded on the right with spaces, so it is not clear what your question is about.Tom

2 Answers

0
votes

You could use REPLICATE(). In the code below, the 'TEST' would be your column name.

SELECT 
'TEST'+REPLICATE(' ', 50-LEN('TEST'))
, DATALENGTH('TEST'+REPLICATE(' ', 50-LEN('TEST')))
0
votes

Character variables in SAS are always fixed length and padded on the right with spaces.

data want ;
   length NAME $50 ;
   name='Fred';
run;