<?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: Export csv file delimiter based on character or numeric variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349417#M273528</link>
    <description>Getting a smiley  where the code line should be&lt;BR /&gt;Put ( _all _ )( : ) ;</description>
    <pubDate>Wed, 12 Apr 2017 12:42:58 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2017-04-12T12:42:58Z</dc:date>
    <item>
      <title>Export csv file delimiter based on character or numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349221#M273523</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;i have data which is combination of character, numeric and date value. i want to export this dataset in csv format.&lt;/P&gt;&lt;P&gt;i want to enclose all character values in double quotes, numeric and date values just seperated by comma. data will also have null values for all character/numeric/date values. First line of file will have title/heading&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example data has columns&lt;/P&gt;&lt;P&gt;like Name-Character, DOB date format mmddyy10. and Age is number format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Desired output file&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;title/heading of file&lt;BR /&gt;"Name"&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "DOB"&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,&amp;nbsp; "Age"&lt;BR /&gt;"john, kalan"&amp;nbsp;&amp;nbsp; , &amp;nbsp;&amp;nbsp;&amp;nbsp; 1/1/2017&amp;nbsp;&amp;nbsp; &amp;nbsp; , &amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;BR /&gt;"john kalan"&amp;nbsp;&amp;nbsp;&amp;nbsp; , &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,&lt;BR /&gt;" " &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; , &amp;nbsp; &amp;nbsp;&amp;nbsp; 1/1/2017&amp;nbsp;&amp;nbsp;&amp;nbsp; , &amp;nbsp;&amp;nbsp; &amp;nbsp;3&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>Tue, 11 Apr 2017 18:49:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349221#M273523</guid>
      <dc:creator>sasuser101</dc:creator>
      <dc:date>2017-04-11T18:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: Export csv file delimiter based on character or numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349225#M273524</link>
      <description>&lt;P&gt;Use dlm=',' dsd in the file statement.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 19:06:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349225#M273524</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-04-11T19:06:43Z</dc:date>
    </item>
    <item>
      <title>Re: Export csv file delimiter based on character or numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349240#M273525</link>
      <description>&lt;P&gt;Thanks for your reply, i am using this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;proc export data=&amp;amp;datast&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outfile="test.csv"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dbms=dlm&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; label&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; replace;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; delimiter=',' ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;above is my code. but only character values with&amp;nbsp; comma etc are double quoted but one with spaces are not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;desired output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Name"&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "DOB"&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,&amp;nbsp; "Age"&lt;BR /&gt;"john, kalan"&amp;nbsp;&amp;nbsp; , &amp;nbsp;&amp;nbsp;&amp;nbsp; 1/1/2017&amp;nbsp;&amp;nbsp; &amp;nbsp; , &amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;BR /&gt;"john kalan"&amp;nbsp;&amp;nbsp;&amp;nbsp; , &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,&lt;BR /&gt;" " &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; , &amp;nbsp; &amp;nbsp;&amp;nbsp; 1/1/2017&amp;nbsp;&amp;nbsp;&amp;nbsp; , &amp;nbsp;&amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 20:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349240#M273525</guid>
      <dc:creator>sasuser101</dc:creator>
      <dc:date>2017-04-11T20:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: Export csv file delimiter based on character or numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349336#M273526</link>
      <description>&lt;P&gt;Use this data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
file "test.csv" dlm=',' dsd;
set &amp;amp;datast;
if _n_ = 1 then put '"Name","DOB","Age"';
put name ~ dob age;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Apr 2017 07:00:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349336#M273526</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-04-12T07:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Export csv file delimiter based on character or numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349413#M273527</link>
      <description>&lt;P&gt;For such a specific solution, you might find the EXPORT Procedure fails to meet the need.&lt;BR /&gt;A DATA Step provides all the flexibility you seek and with brevity.&lt;BR /&gt;____________________________&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc contents noprint out= _data_ data= your.data ;
Proc sort; by varnum ; run ;

FILENAME fref "the path/filename.csv" lrecl= 10000 ;
Data _null_ ;
   File fref dsd ;
   Set ;
   Put name ~ @@ ;
Run ;
* the tilde~modilier in PUT statements would "quote" all variables output, including numeric &lt;BR /&gt;  values. As this is not wanted an alternate quoting method is used for the output of the data rows ;
Data _null_ ;
   File fref mod dsd ;
   Set your.data ;
   Format _character_ $quote200. ;
   Put ( _all_ )( : ) ;
run ;
* need to release the file so other apps can open it;
FILENAME fref ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;___________________________________&lt;BR /&gt;That solution is quite generalised but might fail for character variables that are filled wider than 198. &lt;BR /&gt;Also as I defined LRECL= 10000, should column names or data values require a line wider than that these beyond this limit will be lost. The NOTEs in the SASlog will indicate the widest line written providing an easy check.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 12:48:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349413#M273527</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2017-04-12T12:48:19Z</dc:date>
    </item>
    <item>
      <title>Re: Export csv file delimiter based on character or numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349417#M273528</link>
      <description>Getting a smiley  where the code line should be&lt;BR /&gt;Put ( _all _ )( : ) ;</description>
      <pubDate>Wed, 12 Apr 2017 12:42:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349417#M273528</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2017-04-12T12:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: Export csv file delimiter based on character or numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349425#M273529</link>
      <description>b*mm*r&lt;BR /&gt;multiple """</description>
      <pubDate>Wed, 12 Apr 2017 12:54:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349425#M273529</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2017-04-12T12:54:35Z</dc:date>
    </item>
    <item>
      <title>Re: Export csv file delimiter based on character or numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349426#M273530</link>
      <description>a suitable workaround might be to replace the DSD in the second FILE statement with DLM= ',' &lt;BR /&gt;Then you get none of the delimiter protection that DSD provides, which might be OK ;</description>
      <pubDate>Wed, 12 Apr 2017 12:59:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349426#M273530</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2017-04-12T12:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: Export csv file delimiter based on character or numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349429#M273531</link>
      <description>&lt;P&gt;here is my final working code&lt;/P&gt;
&lt;P&gt;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc contents noprint out= _data_ data= your.data ;
Proc sort; by varnum ; run ;

FILENAME fref "%PATH(YOUR)/filename.csv" lrecl= 10000 ;
Data _null_ ;
   File fref dsd ;
   Set ;
   Put name ~ @@ ;
Run ;
* the tilde~modilier in PUT statements would "quote" all variables output, 
  including numeric   values. As this is not wanted an alternate quoting 
  method is used for the output of the data rows ;
Data _null_ ;
   File fref mod dlm=',' ;
   Set your.data ;
   Format _character_ $quote200. ;
   Put ( _all_ )( ~ ) ;
run ;
* need to release the file so other apps can open it;
FILENAME fref ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Apr 2017 13:04:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349429#M273531</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2017-04-12T13:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: Export csv file delimiter based on character or numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349442#M273532</link>
      <description>&lt;PRE&gt;
Try ODS CSV .



filename temp temp;
ods _all_ close;
ods csv file=temp options(quote_by_type='yes');
proc print data=sashelp.class noobs;run;
ods csv close;


data _null_;
infile temp;
input;
put _infile_;
run;



&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Apr 2017 13:32:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349442#M273532</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-04-12T13:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: Export csv file delimiter based on character or numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349453#M273533</link>
      <description>&lt;P&gt;Has anyone of you tried my code?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile datalines4 dlm=';' dsd truncover;
input name :$20. dob : mmddyy10. age;
format dob mmddyy10.;
datalines4;
Frank Jones;1/1/2017;3
Frank,Jones;1/1/2017;3
;;;;
run;

data _null_;
file '$HOME/test.txt' dlm=',' dsd;
set test;
if _n_ = 1 then put '"Name","DOB","Age"';
put name ~ dob age;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;creates this text file:&lt;/P&gt;
&lt;PRE&gt;"Name","DOB","Age"
"Frank Jones",01/01/2017,3
"Frank,Jones",01/01/2017,3
&lt;/PRE&gt;
&lt;P&gt;which is the OP's intention, as I guess.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 13:54:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349453#M273533</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-04-12T13:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: Export csv file delimiter based on character or numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349503#M273535</link>
      <description>&lt;P&gt;Thank you for solution it works as expected.&lt;/P&gt;&lt;P&gt;Only issue i see is&lt;/P&gt;&lt;P&gt;when i do if _n_ = 1 then put statement i have close to 20 columns, so when i export to csv format and if i press enter for names since 20 is lot to read on one line. csv output breaks the line with tab or enter&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;example&lt;/P&gt;&lt;P&gt;if&amp;nbsp; _n_ = 1 then put '"Col1", "Col2",&amp;nbsp;"Col3",&amp;nbsp;"Col4",&amp;nbsp;"Col5",&amp;nbsp;"Col6",&amp;nbsp;"Col7",&amp;nbsp;"Col8",&amp;nbsp;"Col9",&amp;nbsp;"Col10",&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Col11", "Col12",&amp;nbsp;"Col13",&amp;nbsp;"Col14",&amp;nbsp;"Col15",&amp;nbsp;"Col16",&amp;nbsp;"Col17",&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so in csv output there is extra space between Col10 and Col11 and is causing issue in csv file. Is there way to fix it?&lt;/P&gt;&lt;P&gt;example&lt;/P&gt;&lt;P&gt;"Col9","Col10", "Col11","Col12"&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 16:11:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349503#M273535</guid>
      <dc:creator>sasuser101</dc:creator>
      <dc:date>2017-04-12T16:11:57Z</dc:date>
    </item>
    <item>
      <title>Re: Export csv file delimiter based on character or numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349510#M273536</link>
      <description>thanks for solution.</description>
      <pubDate>Wed, 12 Apr 2017 16:27:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349510#M273536</guid>
      <dc:creator>sasuser101</dc:creator>
      <dc:date>2017-04-12T16:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: Export csv file delimiter based on character or numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349512#M273537</link>
      <description>thanks for solution</description>
      <pubDate>Wed, 12 Apr 2017 16:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349512#M273537</guid>
      <dc:creator>sasuser101</dc:creator>
      <dc:date>2017-04-12T16:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: Export csv file delimiter based on character or numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349527#M273538</link>
      <description>&lt;P&gt;Split your put statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put '"col1","col2","col3",'@;
put '"col4","col5","col6"';&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Apr 2017 16:47:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-csv-file-delimiter-based-on-character-or-numeric-variable/m-p/349527#M273538</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-04-12T16:47:36Z</dc:date>
    </item>
  </channel>
</rss>

