<?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: Macro to export sas datset to CSV , with all columns (both numeric and char quoted in double quo in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-sas-datset-to-CSV-with-all-columns-both-numeric/m-p/957346#M373730</link>
    <description>I tried this option , it generates much code than above method</description>
    <pubDate>Mon, 27 Jan 2025 20:01:40 GMT</pubDate>
    <dc:creator>learn_SAS_23</dc:creator>
    <dc:date>2025-01-27T20:01:40Z</dc:date>
    <item>
      <title>Macro to export sas datset to CSV , with all columns (both numeric and char quoted in double quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-sas-datset-to-CSV-with-all-columns-both-numeric/m-p/957305#M373716</link>
      <description>&lt;P&gt;Hello Team ,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Am looking for a generic macro , which exports data from table to CSV , with UTF8 encoding&amp;nbsp; and all data&amp;nbsp; (both numeric and character )&lt;/P&gt;
&lt;P&gt;needs to be quoted in double quotes&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can somebody help with sample code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2025 15:21:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-sas-datset-to-CSV-with-all-columns-both-numeric/m-p/957305#M373716</guid>
      <dc:creator>learn_SAS_23</dc:creator>
      <dc:date>2025-01-27T15:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to export sas datset to CSV , with all columns (both numeric and char quoted in double quo</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-sas-datset-to-CSV-with-all-columns-both-numeric/m-p/957309#M373717</link>
      <description>&lt;P&gt;Before you create a MACRO figure out what SAS code you want the macro to generate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps something like this? First write the header line and then append the data lines.&lt;/P&gt;
&lt;P&gt;So assuming you have defined a fileref named CSV that points to where you want to write the CSV file this code will make a copy of SASHELP.CLASS with quotes around everything.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=sashelp.class(obs=0) out=names; var _all_ ; run;
data _null_;
  file csv dsd lrecl=1000000;
  set names;
  put _name_ ~ @;
run;
data _null_;
  file csv dsd mod lrecl=1000000;
  set sashelp.class;
  put (_all_) (~);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt; 84         data _null_;
 85           infile csv;
 86           input;
 87           put _infile_;
 88         run;
 
 NOTE: The infile CSV is:
       Filename=/saswork/.../#LN00154,
       Owner Name=xxx,Group Name=oda,
       Access Permission=-rw-r--r--,
       Last Modified=27Jan2025:10:52:39,
       File Size (bytes)=611
 
 "Name","Sex","Age","Height","Weight"
 "Alfred","M","14","69","112.5"
 "Alice","F","13","56.5","84"
 "Barbara","F","13","65.3","98"
 "Carol","F","14","62.8","102.5"
 "Henry","M","14","63.5","102.5"
 "James","M","12","57.3","83"
 "Jane","F","12","59.8","84.5"
 "Janet","F","15","62.5","112.5"
 "Jeffrey","M","13","62.5","84"
 "John","M","12","59","99.5"
 "Joyce","F","11","51.3","50.5"
 "Judy","F","14","64.3","90"
 "Louise","F","12","56.3","77"
 "Mary","F","15","66.5","112"
 "Philip","M","16","72","150"
 "Robert","M","12","64.8","128"
 "Ronald","M","15","67","133"
 "Thomas","M","11","57.5","85"
 "William","M","15","66.5","112"
 NOTE: 20 records were read from the infile CSV.
       The minimum record length was 27.
       The maximum record length was 36.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds&lt;/PRE&gt;
&lt;P&gt;To convert into a macro figure out what inputs the macro needs.&amp;nbsp; Perhaps IN for dataset name and OUT for file name?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro qcsv(in,out);
filename csv "&amp;amp;out" encoding='utf-8';
proc transpose data=&amp;amp;in(obs=0); var _all_; run;
data _null_;
  file csv dsd lrecl=1000000;
  set ;
  put _name_ ~ @ ;
run;
data _null_;
  file csv dsd lrecl=1000000;
  set &amp;amp;in;
  put (_all_) (~);
run;
%mend qcsv;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2025 16:00:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-sas-datset-to-CSV-with-all-columns-both-numeric/m-p/957309#M373717</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-27T16:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to export sas datset to CSV , with all columns (both numeric and char quoted in double quo</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-sas-datset-to-CSV-with-all-columns-both-numeric/m-p/957310#M373718</link>
      <description>&lt;P&gt;Why does it have to be a macro?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could just convert all numerics to character variables, and then create the CSV.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2025 16:03:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-sas-datset-to-CSV-with-all-columns-both-numeric/m-p/957310#M373718</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-01-27T16:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to export sas datset to CSV , with all columns (both numeric and char quoted in double quo</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-sas-datset-to-CSV-with-all-columns-both-numeric/m-p/957344#M373728</link>
      <description>Works exactly to my needs , Thanks for your help</description>
      <pubDate>Mon, 27 Jan 2025 20:00:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-sas-datset-to-CSV-with-all-columns-both-numeric/m-p/957344#M373728</guid>
      <dc:creator>learn_SAS_23</dc:creator>
      <dc:date>2025-01-27T20:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to export sas datset to CSV , with all columns (both numeric and char quoted in double quo</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-sas-datset-to-CSV-with-all-columns-both-numeric/m-p/957346#M373730</link>
      <description>I tried this option , it generates much code than above method</description>
      <pubDate>Mon, 27 Jan 2025 20:01:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-sas-datset-to-CSV-with-all-columns-both-numeric/m-p/957346#M373730</guid>
      <dc:creator>learn_SAS_23</dc:creator>
      <dc:date>2025-01-27T20:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to export sas datset to CSV , with all columns (both numeric and char quoted in double quo</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-sas-datset-to-CSV-with-all-columns-both-numeric/m-p/957403#M373748</link>
      <description>&lt;P&gt;You could always just post-process the CSV file to add the quotes.&lt;/P&gt;
&lt;P&gt;Say you have a standard CSV file name have.csv here is code to convert to your non-standard format into a file named want.csv.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile 'have.csv' dsd truncover length=ll column=cc lrecl=1000000;
  file 'want.csv' dsd lrecl=1000000;
  do until(ll&amp;gt;cc);
    input value :$200. @;
    put value ~ @;
  end;
  put;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have some variables that require more than 200 bytes just increase the width on the informat.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2025 23:29:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-sas-datset-to-CSV-with-all-columns-both-numeric/m-p/957403#M373748</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-27T23:29:26Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to export sas datset to CSV , with all columns (both numeric and char quoted in double quo</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-sas-datset-to-CSV-with-all-columns-both-numeric/m-p/957421#M373757</link>
      <description>&lt;P&gt;I know Tom already gave you the solution.&lt;/P&gt;
&lt;P&gt;Here is just an alternative solution, just for having some fun.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods _all_ close;
ods noresults;
/* Quoted_columns=
A list of column numbers that indicate which values should be quoted
*/
ods csv file='c:\temp\temp.csv' options(Quoted_columns='1 2 3 4 5 6 ');
proc print data=sashelp.class noobs;run;
ods csv close;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1738031668165.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104064iA5EEA87F7C8A5ADE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1738031668165.png" alt="Ksharp_0-1738031668165.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2025 02:34:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-sas-datset-to-CSV-with-all-columns-both-numeric/m-p/957421#M373757</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-01-28T02:34:44Z</dc:date>
    </item>
  </channel>
</rss>

