<?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 Iterate a dataset and export ranges of records to files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Iterate-a-dataset-and-export-ranges-of-records-to-files/m-p/276577#M55423</link>
    <description>&lt;P&gt;I have this loop within proc sql that iterates the dataset pulling ranges of deciles to export to files by decile range. &amp;nbsp;The loop works, but including proc export, the loop continues but ony creates the first file. &amp;nbsp;This is contrary towhat I read in&amp;nbsp;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Export-multiple-tables-from-SAS-to-csv/td-p/27090." target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Export-multiple-tables-from-SAS-to-csv/td-p/27090.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro t();&lt;BR /&gt;proc sql outobs=10;&lt;BR /&gt;&lt;BR /&gt;select max(row) into :n&lt;BR /&gt;from Temp7.Deciles;&lt;BR /&gt;&lt;BR /&gt;%do i=1 %to &amp;amp;n.;&lt;BR /&gt;%put &amp;amp;i;&lt;BR /&gt;select&lt;BR /&gt;seg_n,&lt;BR /&gt;start_decile,&lt;BR /&gt;end_decile, file_n, file_nQ&lt;BR /&gt;into :seg_n, :start_decile,:end_decile, :file_n,:file_nQ&lt;BR /&gt;from Temp7.Deciles where row = &amp;amp;i;&lt;BR /&gt;&lt;BR /&gt;/*create table temp7.&amp;amp;seg_0_100.*/&lt;BR /&gt;CREATE TABLE Temp7.&amp;amp;seg. AS&lt;BR /&gt;select distinct&lt;BR /&gt;GST_REF_I,&lt;BR /&gt;sales_str,&lt;BR /&gt;sales_web,&lt;BR /&gt;total_sales,&lt;BR /&gt;&amp;amp;seg_n. as segment_id,&lt;BR /&gt;pull_date&lt;BR /&gt;from SLS_RANK&lt;BR /&gt;where seg_n =&amp;amp;segnameQ. /*parent_seg_n to prevent pulling data for a failed previous run*/&lt;BR /&gt;and overall_quantile between &amp;amp;start_decile. and &amp;amp;end_decile. ;&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc export data=Temp7.&amp;amp;seg.&lt;BR /&gt;(keep=gst_ref_i segment_id pull_date)&lt;BR /&gt;outfile="&amp;amp;path./&amp;amp;file_n."&lt;BR /&gt;dbms=dlm replace;&lt;BR /&gt;delimiter='|';&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;quit;&lt;BR /&gt;%mend t;&lt;/P&gt;</description>
    <pubDate>Fri, 10 Jun 2016 17:59:57 GMT</pubDate>
    <dc:creator>wer61537</dc:creator>
    <dc:date>2016-06-10T17:59:57Z</dc:date>
    <item>
      <title>Iterate a dataset and export ranges of records to files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-a-dataset-and-export-ranges-of-records-to-files/m-p/276577#M55423</link>
      <description>&lt;P&gt;I have this loop within proc sql that iterates the dataset pulling ranges of deciles to export to files by decile range. &amp;nbsp;The loop works, but including proc export, the loop continues but ony creates the first file. &amp;nbsp;This is contrary towhat I read in&amp;nbsp;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Export-multiple-tables-from-SAS-to-csv/td-p/27090." target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Export-multiple-tables-from-SAS-to-csv/td-p/27090.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro t();&lt;BR /&gt;proc sql outobs=10;&lt;BR /&gt;&lt;BR /&gt;select max(row) into :n&lt;BR /&gt;from Temp7.Deciles;&lt;BR /&gt;&lt;BR /&gt;%do i=1 %to &amp;amp;n.;&lt;BR /&gt;%put &amp;amp;i;&lt;BR /&gt;select&lt;BR /&gt;seg_n,&lt;BR /&gt;start_decile,&lt;BR /&gt;end_decile, file_n, file_nQ&lt;BR /&gt;into :seg_n, :start_decile,:end_decile, :file_n,:file_nQ&lt;BR /&gt;from Temp7.Deciles where row = &amp;amp;i;&lt;BR /&gt;&lt;BR /&gt;/*create table temp7.&amp;amp;seg_0_100.*/&lt;BR /&gt;CREATE TABLE Temp7.&amp;amp;seg. AS&lt;BR /&gt;select distinct&lt;BR /&gt;GST_REF_I,&lt;BR /&gt;sales_str,&lt;BR /&gt;sales_web,&lt;BR /&gt;total_sales,&lt;BR /&gt;&amp;amp;seg_n. as segment_id,&lt;BR /&gt;pull_date&lt;BR /&gt;from SLS_RANK&lt;BR /&gt;where seg_n =&amp;amp;segnameQ. /*parent_seg_n to prevent pulling data for a failed previous run*/&lt;BR /&gt;and overall_quantile between &amp;amp;start_decile. and &amp;amp;end_decile. ;&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc export data=Temp7.&amp;amp;seg.&lt;BR /&gt;(keep=gst_ref_i segment_id pull_date)&lt;BR /&gt;outfile="&amp;amp;path./&amp;amp;file_n."&lt;BR /&gt;dbms=dlm replace;&lt;BR /&gt;delimiter='|';&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;quit;&lt;BR /&gt;%mend t;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 17:59:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-a-dataset-and-export-ranges-of-records-to-files/m-p/276577#M55423</guid>
      <dc:creator>wer61537</dc:creator>
      <dc:date>2016-06-10T17:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate a dataset and export ranges of records to files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-a-dataset-and-export-ranges-of-records-to-files/m-p/276592#M55428</link>
      <description>&lt;P&gt;I think it's your proc sql boundaries that are causing the issues. Your loop starts inside the sql step but then the proc export is outside. This won't work. Add a new proc sql inside the loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: You also appear to have an extra parentheses in the code, I've removed it below. I have NOT checked the rest of your code for accuracy, you may still have errors, but your log should help with that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro t();
proc sql outobs=10;

select max(row) into :n
from Temp7.Deciles;
quit;

%do i=1 %to &amp;amp;n.;
%put &amp;amp;i;

proc sql;
select
seg_n,
start_decile,
end_decile, file_n, file_nQ
into :seg_n, :start_decile,:end_decile, :file_n,:file_nQ
from Temp7.Deciles where row = &amp;amp;i;


/*create table temp7.&amp;amp;seg_0_100.*/
CREATE TABLE Temp7.&amp;amp;seg. AS
select distinct
GST_REF_I,
sales_str,
sales_web,
total_sales,
&amp;amp;seg_n. as segment_id,
pull_date
from SLS_RANK
where seg_n =&amp;amp;segnameQ. /*parent_seg_n to prevent pulling data for a failed previous run*/
and overall_quantile between &amp;amp;start_decile. and &amp;amp;end_decile. ;


quit;
 
proc export data=Temp7.&amp;amp;seg.
(keep=gst_ref_i segment_id pull_date)
outfile="&amp;amp;path./&amp;amp;file_n."
dbms=dlm replace;
delimiter='|';
run;
%end;

%mend t;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 19:04:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-a-dataset-and-export-ranges-of-records-to-files/m-p/276592#M55428</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-10T19:04:29Z</dc:date>
    </item>
  </channel>
</rss>

