0
votes

I have a data set that I have created and it needs to be formatted to have trailing/padded spaces to the specified number of characters.

Below are the field names from the STG data set.

'Social Security Number (SSN)'n
'Date of Birth'n 
'Last Name'n 
'First Name'n 

SSN must start at position 1 and only be 9 characters long (position 1-9)

DOB must start at position 10 and be 8 characters long (position 10-17)

Last Name must start at position 18 and be 26 characters long (position 18-43)

First Name must start at pisition 44 and be 20 characters long (position 44-63)

so on and so forth.

When exported, I need to be able to see the padded/trailing spaces stored in the string. All my fields are formatted as character.

What is the best way to approach this? I've tried specify length and subpad in a data step but when exported, the trailing spaces are lost.

1
What are you creating? A text file?Tom
Yes, it would be a text file. It needs to be uploaded to a site which requires the format to be as such.user1590497
Show example input data and expected output file format.Tom

1 Answers

1
votes

It is pretty trivial to generate a fixed column text file. Just use the PUT statement.

You can force fixed length lines by writing a space into the last column before writing the actual values. That will insure that all lines are padded to at least that length.

 data _null_;
    file 'mydata.txt'  ;
    set have;
    put @63 ' '
      @ 1 SSN $9.
      @10 DOB yymmdd8.
      @18 LAST_NAME $26.
      @44 FIRST_NAME $20.
    ;
 run;