Write and run SAS programs in your web browser

Trailing blanks for text file export

Reply
Contributor
Posts: 57

Trailing blanks for text file export

Hi there,

 

I am generating an output file with a heading. There are numerous columns concateneated together below. After these I need to add blank spacing of 40 characters so the file will upload in a set format to external area.

 

Any ideas on how I can manipulate the current file as SAS seems to remove blanks on export.

 

 

proc sql;
create view work.W4NV5KA as
select RecordType||UndertakingID||ContactName||ContactPhone||Email||PUT(Date, yymmddn8.) as Heading
from &SYSLAST
;
quit;

PROC PRINT DATA=work.W4NV5KA;
RUN;

PROC EXPORT DATA=work.W4NV5KA
OUTFILE="C:\test.txt"
DBMS=TAB REPLACE;
PUTNAMES=NO; /* must be set to no to hide the column heading of the variable in the header section of the file.*/
RUN;
PROC PRINT;
RUN;

 

 

Thanks,

Aidan 

 

Esteemed Advisor
Posts: 5,198

Re: Trailing blanks for text file export

Perhaps you could try to use FILENAME with RECFM=F.

Data never sleeps
Contributor
Posts: 57

Re: Trailing blanks for text file export

Would you have an example of how I could apply this to the current code?

 

Thanks

Esteemed Advisor
Esteemed Advisor
Posts: 7,207

Re: Trailing blanks for text file export

Sorry, its not clear to me what:

"these I need to add blank spacing of 40 characters so the file will upload in a set format to external area."

 

This means?  Most programs read string in until a certain delimiter, then it doens't matter what length things are.  What exactly is it your trying to do, and if your coming up with your own file format structure, why does one of the standardly adopted file formats (such as CSV, XML etc.) not support your requirements?  Far simpler to use something already standard.

Contributor
Posts: 57

Re: Trailing blanks for text file export

Hi there

 

It has to be a text file to meet requirements so I need to stick with that I have to date

Thanks

Aidan

Grand Advisor
Posts: 10,210

Re: Trailing blanks for text file export

Instead of "add 40 spaces" think "set the fixed length of the output line"; That is the comibination LRECL= and RECFM=F with the FILE statement. Use the LRECL option to set the output line length. Coupled with the RECFM=F (fixed record format) then every line of the output file will be the length you specify. If there is nothing actually put in those columns at the end then the record is padded with blanks to make it the desired length.

Ask a Question
Discussion stats
  • 5 replies
  • 179 views
  • 0 likes
  • 4 in conversation