<?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: Observation Selection in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Observation-Selection/m-p/43013#M11201</link>
    <description>Hello Lionfish,&lt;BR /&gt;
&lt;BR /&gt;
I recommend you to take a SAS macro course to understand my code. It is necessary to know this to effectively porgram in SAS.&lt;BR /&gt;
&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR&lt;BR /&gt;
&lt;BR /&gt;
P.S. %put in this context outputs macrovariable values into LOG.</description>
    <pubDate>Wed, 06 Apr 2011 14:29:26 GMT</pubDate>
    <dc:creator>SPR</dc:creator>
    <dc:date>2011-04-06T14:29:26Z</dc:date>
    <item>
      <title>Observation Selection</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Observation-Selection/m-p/43010#M11198</link>
      <description>Hello all,&lt;BR /&gt;
&lt;BR /&gt;
I am trying to figure out how I would be able to select observations from a data set so that I may do some calculations. Might be easier if I show you the coding, so here it goes:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Data compare;&lt;BR /&gt;
do i=1 to 10;&lt;BR /&gt;
xt=0.7*rannor(0);;&lt;BR /&gt;
if xt GE 0 then xt=1;&lt;BR /&gt;
else xt=0;&lt;BR /&gt;
output;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
proc print data=compare;&lt;BR /&gt;
ID i;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
So I end up with a data set of xt with 10 observations.&lt;BR /&gt;
&lt;BR /&gt;
What I would like to do is find the cumulative sum of the xt observations (is it xsum + xt?), the sum of the first and last observation in the set xt (not manually, my actual data set has 1000+ points), and the sum of the pairs x0*x1, x1*x2 (otherwise noted as x(i)*x(i-1) in math terms). After that I'd like to use a formula with all those sums.&lt;BR /&gt;
&lt;BR /&gt;
I've tried making an array, but I end up with a nxn table rather than a nx1 style table. I'm rather new at this so I am not sure if there is a way to do this.&lt;BR /&gt;
&lt;BR /&gt;
Any ideas? &lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance.</description>
      <pubDate>Mon, 04 Apr 2011 00:19:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Observation-Selection/m-p/43010#M11198</guid>
      <dc:creator>Lionfish</dc:creator>
      <dc:date>2011-04-04T00:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: Observation Selection</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Observation-Selection/m-p/43011#M11199</link>
      <description>Hello Lionfish,&lt;BR /&gt;
&lt;BR /&gt;
This is a solution below. Sum and fisrt/last are in the STAT dataset, products are in the R dataset. I've changed your compare dataset for debugging purposes.&lt;BR /&gt;
[pre]&lt;BR /&gt;
data compare;&lt;BR /&gt;
do i=1 to 10;&lt;BR /&gt;
xt=i**2;&lt;BR /&gt;
output;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  set compare end=e;&lt;BR /&gt;
  xsum+xt;&lt;BR /&gt;
  if _n_=1 then call SYMPUTX ('firstx',xt);&lt;BR /&gt;
  if e     then do; &lt;BR /&gt;
    call SYMPUTX ('xsum',xsum);&lt;BR /&gt;
    call SYMPUTX ('lastx',xt);&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
%put xsum=&amp;amp;xsum firstx=&amp;amp;firstx lastx=&amp;amp;lastx;&lt;BR /&gt;
data stat;&lt;BR /&gt;
  xsum=&amp;amp;xsum;&lt;BR /&gt;
  firstx=&amp;amp;firstx;&lt;BR /&gt;
  lastx=&amp;amp;lastx;&lt;BR /&gt;
run;&lt;BR /&gt;
data r;&lt;BR /&gt;
  set compare;&lt;BR /&gt;
  xij=xt*LAG(xt);&lt;BR /&gt;
run; &lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Tue, 05 Apr 2011 15:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Observation-Selection/m-p/43011#M11199</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-04-05T15:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Observation Selection</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Observation-Selection/m-p/43012#M11200</link>
      <description>Hi there,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for the sol. I had did something completely different in the end, with arrays. I like what you did though, I believe those are some type of macro with the %? I should learn those, thanks again!&lt;BR /&gt;
&lt;BR /&gt;
My code if interested:&lt;BR /&gt;
&lt;BR /&gt;
[start]&lt;BR /&gt;
data ZC;&lt;BR /&gt;
do ts = 1 to 500;&lt;BR /&gt;
z = 0;&lt;BR /&gt;
array a(1050) X01-X1050;&lt;BR /&gt;
do i=1 to 1050;&lt;BR /&gt;
a(i)=0.7*z + rannor(0);&lt;BR /&gt;
if a(i) GE 0 then a(i)=1;&lt;BR /&gt;
else a(i)=0;&lt;BR /&gt;
S = sum(of X01-X1050);&lt;BR /&gt;
H = sum(of X01 X1050);&lt;BR /&gt;
R = (X02-X01)**2;&lt;BR /&gt;
PhiZC = cos(constant('pi')*(2*S-2*R-H)/(1049));&lt;BR /&gt;
MSEzc=(PhiZC-0.7)**2;&lt;BR /&gt;
F = (sum(of X02-X1050))**2;&lt;BR /&gt;
PhiLSE = R / F;&lt;BR /&gt;
MSElse=(PhiLSE - 0.7)**2;&lt;BR /&gt;
drop i ts;&lt;BR /&gt;
end;&lt;BR /&gt;
output;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc means data = ZC;&lt;BR /&gt;
var MSEzc MSElse;&lt;BR /&gt;
run;&lt;BR /&gt;
[end]</description>
      <pubDate>Wed, 06 Apr 2011 12:26:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Observation-Selection/m-p/43012#M11200</guid>
      <dc:creator>Lionfish</dc:creator>
      <dc:date>2011-04-06T12:26:47Z</dc:date>
    </item>
    <item>
      <title>Re: Observation Selection</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Observation-Selection/m-p/43013#M11201</link>
      <description>Hello Lionfish,&lt;BR /&gt;
&lt;BR /&gt;
I recommend you to take a SAS macro course to understand my code. It is necessary to know this to effectively porgram in SAS.&lt;BR /&gt;
&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR&lt;BR /&gt;
&lt;BR /&gt;
P.S. %put in this context outputs macrovariable values into LOG.</description>
      <pubDate>Wed, 06 Apr 2011 14:29:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Observation-Selection/m-p/43013#M11201</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-04-06T14:29:26Z</dc:date>
    </item>
  </channel>
</rss>

