<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: TAB delimited file Inserts Spaces in Empty Cells in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/TAB-delimited-file-Inserts-Spaces-in-Empty-Cells/m-p/885573#M349953</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;you could simply use proc export&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC EXPORT DATA=test(rename=(ACCOUNTID=A STATUS=B AMOUNT=C REASON_TO_REPORT=X))
   OUTFILE="&amp;amp;Out_File_Location./abc.txt"
   DBMS=TAB REPLACE;
   PUTNAMES=YES;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 20 Jul 2023 08:39:01 GMT</pubDate>
    <dc:creator>Oligolas</dc:creator>
    <dc:date>2023-07-20T08:39:01Z</dc:date>
    <item>
      <title>TAB delimited file Inserts Spaces in Empty Cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TAB-delimited-file-Inserts-Spaces-in-Empty-Cells/m-p/885561#M349947</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am trying to export some data into a TAB delimited file and it inserts space into every empty cell. How can we get rid of that space?&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Code:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table test as select
	 AccountID
	,'P' 							as STATUS
	,'' 							as AMOUNT				
	,'' 							as REASON_TO_REPORT
	from  XYZ
quit;

data _null_; 
    set test; 
      file "&amp;amp;Out_File_Location./abc.txt"	dlm='	';
   	  if _n_=1 then put 'A	B	C	D   X';

      put   ACCOUNTID STATUS AMOUNT REASON_TO_REPORT; 
 run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Results&lt;/STRONG&gt;&lt;/U&gt;(Notepad++)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Balli_0-1689827930708.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85934i8EAB28F60F1B9405/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Balli_0-1689827930708.png" alt="Balli_0-1689827930708.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2023 04:40:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TAB-delimited-file-Inserts-Spaces-in-Empty-Cells/m-p/885561#M349947</guid>
      <dc:creator>Balli</dc:creator>
      <dc:date>2023-07-20T04:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: TAB delimited file Inserts Spaces in Empty Cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TAB-delimited-file-Inserts-Spaces-in-Empty-Cells/m-p/885573#M349953</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;you could simply use proc export&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC EXPORT DATA=test(rename=(ACCOUNTID=A STATUS=B AMOUNT=C REASON_TO_REPORT=X))
   OUTFILE="&amp;amp;Out_File_Location./abc.txt"
   DBMS=TAB REPLACE;
   PUTNAMES=YES;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2023 08:39:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TAB-delimited-file-Inserts-Spaces-in-Empty-Cells/m-p/885573#M349953</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2023-07-20T08:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: TAB delimited file Inserts Spaces in Empty Cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TAB-delimited-file-Inserts-Spaces-in-Empty-Cells/m-p/885578#M349956</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dlm='09'x&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so that that your SAS source editor doesn't parse the quoted tab character as simple white space.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2023 10:09:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TAB-delimited-file-Inserts-Spaces-in-Empty-Cells/m-p/885578#M349956</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-07-20T10:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: TAB delimited file Inserts Spaces in Empty Cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TAB-delimited-file-Inserts-Spaces-in-Empty-Cells/m-p/885583#M349958</link>
      <description>Add DSD option in FILE statement.&lt;BR /&gt;&lt;BR /&gt;      file "c:\temp\abc.txt" dlm='09'x dsd;</description>
      <pubDate>Thu, 20 Jul 2023 11:35:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TAB-delimited-file-Inserts-Spaces-in-Empty-Cells/m-p/885583#M349958</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-07-20T11:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: TAB delimited file Inserts Spaces in Empty Cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TAB-delimited-file-Inserts-Spaces-in-Empty-Cells/m-p/885596#M349962</link>
      <description>&lt;P&gt;That is what the DSD option on the FILE statement is for.&amp;nbsp; It will write missing values as no characters at all.&amp;nbsp; It will also add quotes around any value that contains the delimiter (and given that your source file is full of literal tab characters there is definitely a non-zero chance that one or more of you variable values will actually end up containing tab characters).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also: Do not insert literal TAB characters into code.&amp;nbsp; They will not survive editing.&amp;nbsp; And they make the code un-readable by humans.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1689855489818.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85941i7E80DD212CAD2CFD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1689855489818.png" alt="Tom_0-1689855489818.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you want when the dataset TEST is empty?&amp;nbsp; Currently your code will write nothing to the file.&amp;nbsp; Do you want it to write the header line even when the file is empty?&amp;nbsp; If so you need to move that PUT statement BEFORE the SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test ;
  accountid=17484;
  status='P';
  amount=.;
  reason_to_report=' ';
  keep accountid status amount reason_to_report;
run;

filename out temp;

data _null_; 
  file out dsd dlm='09'x;
  if _n_=1 then put 'A' '09'x 'B' '09'x 'C' '09'x 'D' '09'x 'X';
  set test; 
  put ACCOUNTID  AMOUNT REASON_TO_REPORT STATUS; 
run; 

data _null_;
  infile out;
  input;
  list;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And you can see that the tabs are there and nothing is present for the missing values.&lt;/P&gt;
&lt;PRE&gt;104  option generic;
105  data _null_;
106    infile out;
107    input;
108    list;
109  run;

NOTE: The infile OUT is:
      (system-specific pathname),
      (system-specific file attributes)

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0

1   CHAR  A.B.C.D.X 9
    ZONE  404040405
    NUMR  192939498

2   CHAR  17484...P 9
    ZONE  333330005
    NUMR  174849990
NOTE: 2 records were read from the infile (system-specific pathname).
      The minimum record length was 9.
      The maximum record length was 9.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2023 12:28:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TAB-delimited-file-Inserts-Spaces-in-Empty-Cells/m-p/885596#M349962</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-20T12:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: TAB delimited file Inserts Spaces in Empty Cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TAB-delimited-file-Inserts-Spaces-in-Empty-Cells/m-p/885722#M350021</link>
      <description>Thanks Tom for the detailed explanation.</description>
      <pubDate>Thu, 20 Jul 2023 23:40:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TAB-delimited-file-Inserts-Spaces-in-Empty-Cells/m-p/885722#M350021</guid>
      <dc:creator>Balli</dc:creator>
      <dc:date>2023-07-20T23:40:04Z</dc:date>
    </item>
    <item>
      <title>Re: TAB delimited file Inserts Spaces in Empty Cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TAB-delimited-file-Inserts-Spaces-in-Empty-Cells/m-p/885723#M350022</link>
      <description>Thank Ksharp for your reply. It works &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 20 Jul 2023 23:41:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TAB-delimited-file-Inserts-Spaces-in-Empty-Cells/m-p/885723#M350022</guid>
      <dc:creator>Balli</dc:creator>
      <dc:date>2023-07-20T23:41:11Z</dc:date>
    </item>
  </channel>
</rss>

