<?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: Force set statement to first observation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Force-set-statement-to-first-observation/m-p/713344#M220061</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/358374"&gt;@Paul_de_Barros&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may want to use the POINT= option of the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=p00hxg3x8lwivcn1f0e9axziw57y.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;SET statement&lt;/A&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example (producing &lt;FONT face="courier new,courier"&gt;8*8=64&lt;/FONT&gt; pairs):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data pairs;
set JustIndex nobs=_n;
do _i=1 to _n;
  set JustIndex(rename=(ID=ID2)) point=_i;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;By changing the DO statement to&lt;/P&gt;
&lt;PRE&gt;do _i=&lt;STRONG&gt;_n_+1&lt;/STRONG&gt; to _n;&lt;/PRE&gt;
&lt;P&gt;you can limit the output to the &lt;FONT face="courier new,courier"&gt;comb(8,2)=28&lt;/FONT&gt; pairs (ID=i, ID2=j) with i&amp;lt;j.&lt;/P&gt;</description>
    <pubDate>Fri, 22 Jan 2021 13:39:48 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2021-01-22T13:39:48Z</dc:date>
    <item>
      <title>Force set statement to first observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Force-set-statement-to-first-observation/m-p/713335#M220055</link>
      <description>&lt;P&gt;I would like to take a data set with 1 column containing distinct entries and expand it by making pairs of distinct entries.&amp;nbsp; I thought i could do this by placing a second SET statement referencing the same data set inside a DO WHILE loop, but it's not working.&amp;nbsp; The issue is that the buffer (or whatever) for the second SET statement appears to be preserved over iterations of the implicit loop of the DATA step.&amp;nbsp; Is there a way to force a SET statement to read from the first observation, regardless of the iteration of the DATA step?&amp;nbsp; My code is below with lots of PUT statements to show what's happening in the log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data JustIndex;
	input ID @@;
	datalines;
1 2 3 4 5 6 7 8
;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data pairs;
	set JustIndex;
	innerIndex = 1;
	put 'Before loop: ' _all_;
	Do while (innerIndex &amp;lt; _N_);
		put 'looping ' innerIndex;
		set JustIndex;
		ID2 = ID;
		output;
		innerIndex = innerIndex  + 1;
	end;
	put 'After loop:  ' _all_;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And here's the log for the second DATA step:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Before loop: ID=1 innerIndex=1 ID2=. _ERROR_=0 _N_=1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;After loop: ID=1 innerIndex=1 ID2=. _ERROR_=0 _N_=1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Before loop: ID=2 innerIndex=1 ID2=. _ERROR_=0 _N_=2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;looping 1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;After loop: ID=1 innerIndex=2 ID2=1 _ERROR_=0 _N_=2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Before loop: ID=3 innerIndex=1 ID2=. _ERROR_=0 _N_=3&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;looping 1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;looping 2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;After loop: ID=3 innerIndex=3 ID2=3 _ERROR_=0 _N_=3&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Before loop: ID=4 innerIndex=1 ID2=. _ERROR_=0 _N_=4&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;looping 1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;looping 2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;looping 3&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;After loop: ID=6 innerIndex=4 ID2=6 _ERROR_=0 _N_=4&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Before loop: ID=5 innerIndex=1 ID2=. _ERROR_=0 _N_=5&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;looping 1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;looping 2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;looping 3&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;As you can see, the DO WHILE loop runs exactly 9 times.&amp;nbsp; On the 9th time, the inner SET statement hits the end of the data set, causing the DATA step to terminate.&amp;nbsp; The point of the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;innerIndex &amp;lt; _N_&lt;/STRONG&gt;&lt;/FONT&gt; condition was to prevent the inner SET statement from ever hitting the end of the data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2021 13:10:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Force-set-statement-to-first-observation/m-p/713335#M220055</guid>
      <dc:creator>Paul_de_Barros</dc:creator>
      <dc:date>2021-01-22T13:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: Force set statement to first observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Force-set-statement-to-first-observation/m-p/713338#M220056</link>
      <description>&lt;P&gt;Can you post your desired result? Is what you're after a cartesian product?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data JustIndex;
	input ID @@;
	datalines;
1 2 3 4 5 6 7 8
;
run;

data want;
   set JustIndex;
   do i=1 to n;
      set JustIndex(rename = ID = ID2) point = i nobs = n;
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Obs ID ID2 
1   1  1 
2   1  2 
3   1  3 
4   1  4 
5   1  5 
6   1  6 
7   1  7 
8   1  8 
9   2  1 
10  2  2
.
.
.&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Jan 2021 13:48:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Force-set-statement-to-first-observation/m-p/713338#M220056</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-01-22T13:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: Force set statement to first observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Force-set-statement-to-first-observation/m-p/713344#M220061</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/358374"&gt;@Paul_de_Barros&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may want to use the POINT= option of the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=p00hxg3x8lwivcn1f0e9axziw57y.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;SET statement&lt;/A&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example (producing &lt;FONT face="courier new,courier"&gt;8*8=64&lt;/FONT&gt; pairs):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data pairs;
set JustIndex nobs=_n;
do _i=1 to _n;
  set JustIndex(rename=(ID=ID2)) point=_i;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;By changing the DO statement to&lt;/P&gt;
&lt;PRE&gt;do _i=&lt;STRONG&gt;_n_+1&lt;/STRONG&gt; to _n;&lt;/PRE&gt;
&lt;P&gt;you can limit the output to the &lt;FONT face="courier new,courier"&gt;comb(8,2)=28&lt;/FONT&gt; pairs (ID=i, ID2=j) with i&amp;lt;j.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2021 13:39:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Force-set-statement-to-first-observation/m-p/713344#M220061</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-01-22T13:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: Force set statement to first observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Force-set-statement-to-first-observation/m-p/713362#M220065</link>
      <description>&lt;P&gt;Thank you,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;.&amp;nbsp; The POINT= option was exactly what I was looking for.&lt;/P&gt;&lt;P&gt;Sorry if I wasn't clear about the desired output; I wasn't trying to get the full Cartesian product, just the unique unordered combinations.&lt;/P&gt;&lt;P&gt;My resulting solution was a little different from what you both suggested.&amp;nbsp; In case you are interested, here's what I did:&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="courier new,courier"&gt;data pairs;
	set JustIndex nobs=_n;
	Do _i=_N_+1 to _n;
		set JustIndex(rename=(ID=ID2)) point=_i;
		output;
	end;
run;&lt;/FONT&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Jan 2021 14:40:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Force-set-statement-to-first-observation/m-p/713362#M220065</guid>
      <dc:creator>Paul_de_Barros</dc:creator>
      <dc:date>2021-01-22T14:40:04Z</dc:date>
    </item>
  </channel>
</rss>

