sri
sri

Reputation: 1

SAS - Output text file doesn't contain the exact spaces

I am trying to write a SAS output file from a work table. I inserted blank values ' ' (contains 4 spaces) for the output column. However, when I output to a text file, it shows only one space '' (Example below, Sequence_number) Is there a way I can include a format and have all the four spaces as output: Something like below(sequence number should have 4 blank spaces)

 create table work.mech_temp_final as
      (select put(mt.chq_srl_nbr, z12.) as chq_srl_nbr
            , "    " as sequence_number
       from work.settl mt); 

output as

12345|    |     

rather than

12345||

Upvotes: 0

Views: 621

Answers (2)

Richard
Richard

Reputation: 27508

You can write directly write a fixed layout file from Proc SQL by using ODS LISTING. Not recommended for many use cases.

Example:

title;
options nocenter nodate nonumber ps=max formchar='  ';

ods listing file='c:\temp\listing.txt';

proc sql;
  select 
    name format=$CHAR12.
  , ' '
  , age format=z9.
  from sashelp.class;
quit;

ods listing close;

Upvotes: 1

Stu Sztukowski
Stu Sztukowski

Reputation: 12909

Instead of using PROC EXPORT, use a data step with a put statement to generate the pipe-delimited file. If you have many variables to output, you can generate the required code using dictionary tables, save it to a macro variable, and use it in the put statement.

data _null_;
    set sashelp.cars(rename=(horsepower = chq_srl_nbr) );
    file "C:\test.txt";

    sequence_number = '    ';

    /* Create a header */
    if(_N_ = 1) then put 'chq_srl_nbr|sequence_number';

    /* Write data in the desired format */
    put chq_srl_nbr z12. '|' sequence_number $char4.;
run;

Upvotes: 1

Related Questions