<?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: Do loop error, unintended record show up in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-unintended-record-show-up/m-p/346339#M79856</link>
    <description>&lt;P&gt;You can simplify it even more:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want (drop=i);
  set have_var1;
  do i=1 to nobs;
    set have_var2  nobs=nobs point=i;
    output;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
    <pubDate>Fri, 31 Mar 2017 21:08:59 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-03-31T21:08:59Z</dc:date>
    <item>
      <title>Do loop error, unintended record show up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-unintended-record-show-up/m-p/346334#M79852</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I want to make a combination of 2 files, 1 record of this file and 1 record of other file.&lt;/P&gt;
&lt;P&gt;So with 3 records in 1 file and 2 records in other file, I should have 6 combinations.&lt;/P&gt;
&lt;P&gt;I write the usual code and suddendy there are few unintended records created in final file (the last 2 record in file want)&lt;/P&gt;
&lt;P&gt;The code is so straightforward but I cant find the cause.&lt;/P&gt;
&lt;P&gt;Could anyone please have a look and help me fix it?&lt;/P&gt;
&lt;P&gt;Many thanks.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have_var1; 
input a_name $ a_value b_name $ b_value;
datalines;
a 4 b 5
a 4 c 9
b 5 c 9

;run;


data have_var2; 
input c_name $ c_value;
datalines;
c 90
d 100
;run;

	*Create combination of any 2 row from 2 file;
		data want;									
		set have_var1 nobs=totalobs1;
		drop i ;
		i+1;
		set have_var2 nobs=totalobs2;
		drop k ;
		k+1;

		do j=i to totalobs1 ;
		set have_var1(keep = a_name a_value b_name b_value) point=j;

		do l=k to totalobs2 ;
		set have_var2(keep = c_name c_value) point=l;
		
			/*if a_name^=c_name and b_name^=c_name then*/

			output;
			end;

		end;
		run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 20:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-unintended-record-show-up/m-p/346334#M79852</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2017-03-31T20:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error, unintended record show up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-unintended-record-show-up/m-p/346336#M79853</link>
      <description>&lt;P&gt;You are making it way too complicated. &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;									
do j=1 to totalobs1 ;
  set have_var1(keep = a_name a_value b_name b_value) point=j nobs=totalobs1;
  do l=1 to totalobs2 ;
    set have_var2(keep = c_name c_value) point=l nobs=totalobs2;
    output;
  end;
end;
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Make sure to add a STOP to prevent it from running for ever. Remember that normal data steps stop when they read past the end of the input files. When using POINT= option it will never read past the end of the input.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 20:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-unintended-record-show-up/m-p/346336#M79853</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-03-31T20:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error, unintended record show up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-unintended-record-show-up/m-p/346339#M79856</link>
      <description>&lt;P&gt;You can simplify it even more:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want (drop=i);
  set have_var1;
  do i=1 to nobs;
    set have_var2  nobs=nobs point=i;
    output;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 21:08:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-unintended-record-show-up/m-p/346339#M79856</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-31T21:08:59Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error, unintended record show up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-unintended-record-show-up/m-p/346340#M79857</link>
      <description>&lt;P&gt;Can't try it from where I am at the moment (hotel room in Venice), but try a SQL cartesian join:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select *
from have_var1, have_var2
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 Mar 2017 21:09:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-unintended-record-show-up/m-p/346340#M79857</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-31T21:09:07Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error, unintended record show up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-unintended-record-show-up/m-p/346343#M79859</link>
      <description>Oh that STOP!&lt;BR /&gt;my code really look ... &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;Thank you.&lt;BR /&gt;HHC&lt;BR /&gt;</description>
      <pubDate>Fri, 31 Mar 2017 21:16:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-unintended-record-show-up/m-p/346343#M79859</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2017-03-31T21:16:44Z</dc:date>
    </item>
  </channel>
</rss>

