<?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: How to Macro PROC EXPORT CVS in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-Macro-PROC-EXPORT-CVS/m-p/625058#M20194</link>
    <description>&lt;P&gt;You told PROC EXPORT to make CSV files, so that is what it made.&amp;nbsp; The only reason it wouldn't look like a CSV file would be if the data only had one variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But don't you normally want to have a period and extension on the filenames. Like .CSV?&amp;nbsp; &amp;nbsp;They way you have it written your code both periods will be used by the macro processor.&amp;nbsp; The first to mark the end of the macro variable I and the second to mark the end of the macro variable DSET1, DSET2, etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;outfile="C:\Users\SAS\Output\&amp;amp;&amp;amp;dset&amp;amp;i...csv"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or better still skip wasting your time and confusing yourself by making all of those macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   if end then call symputx('max',_n_-1);
   set dirlist end=end;
   call execute(catx(' '
,'proc export data=',cats('temp',_n_),'outfile='
,quote(cats('C:\Users\SAS\Output\',scan(file_name,1,'.'),'.csv'))
,'dbms=csv replace;run;'
));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 16 Feb 2020 03:08:52 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-02-16T03:08:52Z</dc:date>
    <item>
      <title>How to Macro PROC EXPORT CVS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-Macro-PROC-EXPORT-CVS/m-p/625056#M20192</link>
      <description>&lt;P&gt;Hi there, I'm trying to export several datasets to csv. I do export some files but they're not in CSV format. They're just 'File'.&amp;nbsp; My code is below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro export;
%do  i =  1 %to &amp;amp;max;
proc export data=temp&amp;amp;i
outfile="C:\Users\SAS\Output\&amp;amp;&amp;amp;dset&amp;amp;i..csv" dbms=csv replace; 
run;

%end;

%mend export;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;amp;&amp;amp;dset &amp;amp;i is a macro var. I created it by the following code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename DIRLIST pipe 'dir "C:\Users\SAS\coded_logs*.csv" /b ';

data dirlist ;
   infile dirlist lrecl=200 truncover;
   input file_name $100.;
run;

data _null_;
   set dirlist end=end;
   count+1;
   call symputx('read'||put(count,4.-l),cats('C:\Users\SAS\',file_name));
   call symputx('dset'||put(count,4.-l),scan(file_name,1,'.'));
   if end then call symputx('max',count);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Feb 2020 02:00:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-Macro-PROC-EXPORT-CVS/m-p/625056#M20192</guid>
      <dc:creator>maxjiang6999</dc:creator>
      <dc:date>2020-02-16T02:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to Macro PROC EXPORT CVS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-Macro-PROC-EXPORT-CVS/m-p/625057#M20193</link>
      <description>&lt;P&gt;&amp;nbsp;Please look at data set DIRLIST and confirm it has the desired values.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you see if you use the command&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;=dset1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are there spaces in the value of &amp;amp;DSET1? are there spaces at the beginning of the value? Does it have the value you want it to have?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that's not it, then use the command&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;aat the beginning of your program and run the code again and then you can look at what is in the log and see if something is not happening the way you want it to happen.&lt;/P&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Sun, 16 Feb 2020 02:53:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-Macro-PROC-EXPORT-CVS/m-p/625057#M20193</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-16T02:53:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to Macro PROC EXPORT CVS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-Macro-PROC-EXPORT-CVS/m-p/625058#M20194</link>
      <description>&lt;P&gt;You told PROC EXPORT to make CSV files, so that is what it made.&amp;nbsp; The only reason it wouldn't look like a CSV file would be if the data only had one variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But don't you normally want to have a period and extension on the filenames. Like .CSV?&amp;nbsp; &amp;nbsp;They way you have it written your code both periods will be used by the macro processor.&amp;nbsp; The first to mark the end of the macro variable I and the second to mark the end of the macro variable DSET1, DSET2, etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;outfile="C:\Users\SAS\Output\&amp;amp;&amp;amp;dset&amp;amp;i...csv"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or better still skip wasting your time and confusing yourself by making all of those macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   if end then call symputx('max',_n_-1);
   set dirlist end=end;
   call execute(catx(' '
,'proc export data=',cats('temp',_n_),'outfile='
,quote(cats('C:\Users\SAS\Output\',scan(file_name,1,'.'),'.csv'))
,'dbms=csv replace;run;'
));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Feb 2020 03:08:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-Macro-PROC-EXPORT-CVS/m-p/625058#M20194</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-16T03:08:52Z</dc:date>
    </item>
  </channel>
</rss>

