<?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: Creating csv with space in columns in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-csv-with-space-in-columns/m-p/875576#M42949</link>
    <description>Dear Sir,&lt;BR /&gt;There is leading space for some rows in second column&lt;BR /&gt;2,3 rows there should be a space before letter A and B&lt;BR /&gt;&lt;BR /&gt;No particular amount&lt;BR /&gt;1 "I BOOKS"                  5000&lt;BR /&gt;2 "   A PLANE"              3000&lt;BR /&gt;3 "   B DOUBLE ROOL" 2000&lt;BR /&gt;4 "II STATENAORY"     1000&lt;BR /&gt;5 "    A PEN"                    500&lt;BR /&gt;6 "    B PENCIL"               500&lt;BR /&gt;</description>
    <pubDate>Sat, 13 May 2023 09:26:42 GMT</pubDate>
    <dc:creator>santhosh</dc:creator>
    <dc:date>2023-05-13T09:26:42Z</dc:date>
    <item>
      <title>Creating csv with space in columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-csv-with-space-in-columns/m-p/875405#M42943</link>
      <description>I need to create .csv output should have space in rows &lt;BR /&gt;Sample output&lt;BR /&gt;No particular amount&lt;BR /&gt;1    I BOOKS         5000&lt;BR /&gt;2          A PLANE  3000&lt;BR /&gt;3          B  DOUBLE ROOL 2000&lt;BR /&gt;4    II STATENAORY   1000&lt;BR /&gt;5          A PEN           500&lt;BR /&gt;6          B  PENCIL     500&lt;BR /&gt;</description>
      <pubDate>Fri, 12 May 2023 08:12:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-csv-with-space-in-columns/m-p/875405#M42943</guid>
      <dc:creator>santhosh</dc:creator>
      <dc:date>2023-05-12T08:12:50Z</dc:date>
    </item>
    <item>
      <title>Re: Creating csv with space in columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-csv-with-space-in-columns/m-p/875417#M42944</link>
      <description>&lt;P&gt;You can do this using option:&lt;/P&gt;
&lt;PRE&gt;delimiter=" ";&lt;/PRE&gt;
&lt;P&gt;for example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data credit;
set sashelp.credit(obs=10);
run;
proc print;

proc export data=credit
    outfile="/home/u61950255/Files/data.csv"
    dbms=csv
    replace;
    delimiter="	";
    putnames=NO;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But beware that it would cause problem when you have space in between the data in the same column.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1685"&gt;@santhosh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look at the data from csv file generated by above code with delimiter=" ";&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MayurJadhav_0-1683886182222.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83914i051C43ABE54B5BC3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MayurJadhav_0-1683886182222.png" alt="MayurJadhav_0-1683886182222.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 10:10:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-csv-with-space-in-columns/m-p/875417#M42944</guid>
      <dc:creator>MayurJadhav</dc:creator>
      <dc:date>2023-05-12T10:10:22Z</dc:date>
    </item>
    <item>
      <title>Re: Creating csv with space in columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-csv-with-space-in-columns/m-p/875446#M42945</link>
      <description>&lt;P&gt;Your desired output does not look like something usable.&amp;nbsp; You appear to have three variables named&amp;nbsp;No, particular, and amount.&amp;nbsp; But some of your data rows appear to have more than 3 values on them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Normally in a delimited text file (like a CSV file) you have to quote values that contain the delimiter.&lt;/P&gt;
&lt;P&gt;So, depending on which value the space belongs to, your file might look like this:&lt;/P&gt;
&lt;PRE&gt;No particular amount
1 "I BOOKS" 5000
2 "A PLANE" 3000
3 "B DOUBLE ROOL" 2000
4 "II STATENAORY" 1000
5 "A PEN" 500
6 "B PENCIL" 500&lt;/PRE&gt;
&lt;P&gt;SAS can generate that type of file using a simple data step with the DSD option of the FILE statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set have;
  file 'mytext_file.txt' dsd dlm=' ';
  if _n_=1 then put 'No particular amount';
  put no particular amount;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 12:32:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-csv-with-space-in-columns/m-p/875446#M42945</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-12T12:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: Creating csv with space in columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-csv-with-space-in-columns/m-p/875576#M42949</link>
      <description>Dear Sir,&lt;BR /&gt;There is leading space for some rows in second column&lt;BR /&gt;2,3 rows there should be a space before letter A and B&lt;BR /&gt;&lt;BR /&gt;No particular amount&lt;BR /&gt;1 "I BOOKS"                  5000&lt;BR /&gt;2 "   A PLANE"              3000&lt;BR /&gt;3 "   B DOUBLE ROOL" 2000&lt;BR /&gt;4 "II STATENAORY"     1000&lt;BR /&gt;5 "    A PEN"                    500&lt;BR /&gt;6 "    B PENCIL"               500&lt;BR /&gt;</description>
      <pubDate>Sat, 13 May 2023 09:26:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-csv-with-space-in-columns/m-p/875576#M42949</guid>
      <dc:creator>santhosh</dc:creator>
      <dc:date>2023-05-13T09:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: Creating csv with space in columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-csv-with-space-in-columns/m-p/875579#M42950</link>
      <description>&lt;P&gt;Your question is a bit underspecified so my answer based on some assumptions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.have;
  infile datalines dsd dlm=' ';
  input no particular:$40. amount;
  datalines;
1 "I BOOKS" 5000
2 " A PLANE" 3000
3 " B DOUBLE ROOL" 2000
4 "II STATENAORY" 1000
5 " A PEN" 500
6 " B PENCIL" 500
;
proc export 
  data=work.have
  outfile= "c:\temp\want.csv"
  dbms=csv
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;c:\temp\want.csv opened with a text editor&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1683970507138.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83940iA0435D9F960D23FF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1683970507138.png" alt="Patrick_0-1683970507138.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2023 09:35:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-csv-with-space-in-columns/m-p/875579#M42950</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-05-13T09:35:14Z</dc:date>
    </item>
    <item>
      <title>Re: Creating csv with space in columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-csv-with-space-in-columns/m-p/875594#M42951</link>
      <description>&lt;P&gt;Leading spaces do not translate well into a delimited file.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To preserve them when reading a file like you could try using the $CHAR informat instead of the normal $ informat.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards dsd dlm=' ' truncover;
  input No particular :$char20. amount;
cards;
1 "I BOOKS" 5000
2 " A PLANE" 3000
3 " B DOUBLE ROOL" 2000
4 "II STATENAORY" 1000
5 " A PEN" 500
6 " B PENCIL" 500
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But to write that back out you will need to NOT use the DSD option on the FILE statement.&lt;/P&gt;
&lt;P&gt;Which means you cannot use PROC EXPORT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So instead just use the $QUOTE. format to add quotes around every string variable, just in case it has any embedded space.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
 file 'want.csv';
 set have;
 if _n_=1 then put 'No particular amount';
 put no particular amount;
 format _character_ $quote.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;No particular amount
1 "I BOOKS" 5000
2 " A PLANE" 3000
3 " B DOUBLE ROOL" 2000
4 "II STATENAORY" 1000
5 " A PEN" 500
6 " B PENCIL" 500
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2023 17:30:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-csv-with-space-in-columns/m-p/875594#M42951</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-13T17:30:06Z</dc:date>
    </item>
  </channel>
</rss>

