<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Export-CSV-File/m-p/58899#M12771</link>
    <description>For your SAS file, use a WHERE statement to create a "filtered" temporary SAS file having only one value of a particular "company" variable. The use that filtered file to export to a CSV.  You can use PROC SQL to generate a set of SAS macro variables, each having a value for the "company" variable, and use a SAS macro approach to repeat the same filter/export code execution for each macro variable condition.&lt;BR /&gt;
&lt;BR /&gt;
You will find useful information at the SAS support website  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt; either using their website SEARCH or using Google search against the SAS.COM website.  Related to this post topic, I have provided one example of a SAS technical conference paper for you to reference:&lt;BR /&gt;
&lt;BR /&gt;
SAS® Macro Variables and Simple Macro Programs&lt;BR /&gt;
Steven First, Katie Ronk, Systems Seminar Consultants, Madison, WI&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi30/130-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/130-30.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Mon, 27 Jul 2009 02:33:52 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-07-27T02:33:52Z</dc:date>
    <item>
      <title>Export - CSV File</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-CSV-File/m-p/58898#M12770</link>
      <description>Hi - &lt;BR /&gt;
&lt;BR /&gt;
I am able to export my data into a csv file.  However, I have multiple companies that make up my dataset along with other variables.  I would like to export the data but have each company's data stored in a separate csv file.  How would I go about accomplishing this task? &lt;BR /&gt;
&lt;BR /&gt;
Thank you</description>
      <pubDate>Mon, 27 Jul 2009 00:25:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-CSV-File/m-p/58898#M12770</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-27T00:25:04Z</dc:date>
    </item>
    <item>
      <title>Re: Export - CSV File</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-CSV-File/m-p/58899#M12771</link>
      <description>For your SAS file, use a WHERE statement to create a "filtered" temporary SAS file having only one value of a particular "company" variable. The use that filtered file to export to a CSV.  You can use PROC SQL to generate a set of SAS macro variables, each having a value for the "company" variable, and use a SAS macro approach to repeat the same filter/export code execution for each macro variable condition.&lt;BR /&gt;
&lt;BR /&gt;
You will find useful information at the SAS support website  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt; either using their website SEARCH or using Google search against the SAS.COM website.  Related to this post topic, I have provided one example of a SAS technical conference paper for you to reference:&lt;BR /&gt;
&lt;BR /&gt;
SAS® Macro Variables and Simple Macro Programs&lt;BR /&gt;
Steven First, Katie Ronk, Systems Seminar Consultants, Madison, WI&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi30/130-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/130-30.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 27 Jul 2009 02:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-CSV-File/m-p/58899#M12771</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-07-27T02:33:52Z</dc:date>
    </item>
    <item>
      <title>Re: Export - CSV File</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-CSV-File/m-p/58900#M12772</link>
      <description>An alternative is to export from a data step and use the filevar= option:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data T;&lt;BR /&gt;
 COMPANY='A'; X=1; output;&lt;BR /&gt;
 COMPANY='A'; X=2; output;&lt;BR /&gt;
 COMPANY='B'; X=3; output;&lt;BR /&gt;
&lt;BR /&gt;
data T1;&lt;BR /&gt;
  set T;&lt;BR /&gt;
  FILE='f:\' || COMPANY || '.txt' ;&lt;BR /&gt;
  file OUT filevar=FILE mod dlm=',';&lt;BR /&gt;
  put COMPANY X;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 27 Jul 2009 03:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-CSV-File/m-p/58900#M12772</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-07-27T03:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: Export - CSV File</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-CSV-File/m-p/58901#M12773</link>
      <description>Hi,&lt;BR /&gt;
Another approach, to those already listed, is to use ODS. ODS CSV allows you to specify a NEWFILE= option, which tells ODS the interval or break point at which a new output file should be started. So, if you use a BY statement, for example, then NEWFILE=BYGROUP would cause a new output file for every BY group.&lt;BR /&gt;
 &lt;BR /&gt;
Here's an example:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sort data=sashelp.shoes out=shoes;&lt;BR /&gt;
  by region;&lt;BR /&gt;
  where region in ('Asia', 'Canada', 'Pacific');&lt;BR /&gt;
run;&lt;BR /&gt;
                              &lt;BR /&gt;
ods csv file='c:\temp\reg1.csv' newfile=bygroup;&lt;BR /&gt;
  proc print data=shoes;&lt;BR /&gt;
    by region;&lt;BR /&gt;
    var region subsidiary sales inventory returns;&lt;BR /&gt;
  run;&lt;BR /&gt;
ods csv close;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                       &lt;BR /&gt;
This code will create 3 output files, REG1.CSV, REG2.CSV, and REG3.CSV -- so if you are OK with the numbered naming convention, then ODS CSV provides another alternative.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 27 Jul 2009 21:11:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-CSV-File/m-p/58901#M12773</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-07-27T21:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: Export - CSV File</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-CSV-File/m-p/58902#M12774</link>
      <description>if you were to use a data step FILE statement to create the files, then the FILEVAR= option would allow you to name the files dynamically.&lt;BR /&gt;
In the on line documentation is an example doing just this, at &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000171874.htm#a000220945" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000171874.htm#a000220945&lt;/A&gt; .&lt;BR /&gt;
Also in on-line documentation and also in the Forum archives, there should be examples of how to generate csv in a data step, but the simplest (imho) is based on these  statements[pre]     file yourfile DSD lrecl=10000 ;&lt;BR /&gt;
     set yourData ;&lt;BR /&gt;
     put (_all_)(:) ;[/pre]that PUT statement places the variable data in default formats and in default column order, into csv-format and with protection for any delimiters (commas) emebdded in data values. &lt;BR /&gt;
To the FILE statement you add the FILEVAR= support.&lt;BR /&gt;
Extend the SET statement with [pre]      BY company ;[/pre]And, [pre]     if FIRST.company then do ;&lt;BR /&gt;
        destination = "&amp;amp;path\"!!compress(company)!!'.csv' ;&lt;BR /&gt;
        file yourfile FILEVAR= destination ;&lt;BR /&gt;
        put &amp;amp;headings ;&lt;BR /&gt;
     end ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
well, something like that&lt;BR /&gt;
 &lt;BR /&gt;
The &amp;amp;headings glosses over that issue. Although you can generate a macro variable &amp;amp;headings containing the comma-delimited quoted headings (varnames or var labels when present) with [pre]PROC SQL noprint ;&lt;BR /&gt;
      select quote( quote( trim( coalescec( LABEL, NAME ))))&lt;BR /&gt;
        into :headings separated by " ', ' "&lt;BR /&gt;
        from dictionary.columns&lt;BR /&gt;
       where libname = "%upcase(yourLib)"&lt;BR /&gt;
         and memname = "%upcase(yourMemberName)"&lt;BR /&gt;
    order by varnum&lt;BR /&gt;
          ;[/pre]&lt;BR /&gt;
 a neater alternative that creates the heading within the same data step, was demonstrated by the user data _null_; in these Forums at &lt;A href="http://support.sas.com/forums/click.jspa?searchID=-1&amp;amp;messageID=18398" target="_blank"&gt;http://support.sas.com/forums/click.jspa?searchID=-1&amp;amp;messageID=18398&lt;/A&gt; .&lt;BR /&gt;
 &lt;BR /&gt;
"how many ways are there, to skin a cat?"&lt;BR /&gt;
 &lt;BR /&gt;
(not that I want to;-)&lt;BR /&gt;
 &lt;BR /&gt;
PeterC&lt;BR /&gt;
(and, by the way, using this data step method to generate CSV data, is faster than the ODS CSV tagset method which becomes very relevant for volumes in the thousands-of-&lt;B&gt;cells&lt;/B&gt; )</description>
      <pubDate>Wed, 29 Jul 2009 11:02:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-CSV-File/m-p/58902#M12774</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-07-29T11:02:26Z</dc:date>
    </item>
  </channel>
</rss>

