1
votes

I am trying to save a numeric-with-decimal-places(f8.6) variable from an SPSS file into a fixed ASCII file. The goal is to write it into certain columns of the ASCII (21 to 30).

    WRITE OUTFILE='C:\misc\ascii.dat'
      ENCODING='UTF8'
      TABLE /1
    variable 21-30.
exe.

writes to the correct positions, but not with decimals.

variable 21-30 (f)

does the same thing.

variable (f8.6) 

saves with decimals, but on positions 1 to 10.

variable 21-30 (f8.6)

results in an error, because apparently you cannot specify both columns and format.

I know two workarounds, but both involve additional data editing, which I'd rather not do:

  1. Convert variable to string and save it as string - but I am not sure about the implications (encoding, decimal places, or whatever other thing I am not even considering)

  2. add an empty string variable with length of 20 before my variable.

But is there a straightforward way of doing this, without workarounds ?

1

1 Answers

1
votes

You can add the 20 spaces in the command itself, like this:

WRITE OUTFILE='C:\misc\ascii.dat'
      ENCODING='UTF8'
      TABLE / '                    '  YourNumVar (f8.6) .
exe.