<?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: Simple Question on extracting rows in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Simple-Question-on-extracting-rows/m-p/7734#M180</link>
    <description>Hi,&lt;BR /&gt;
   I think the following code is helpful to store '5'  permanantly; &lt;BR /&gt;
  Proc sql;&lt;BR /&gt;
select(col1) into:a  from libref.datasetname where col1=5;&lt;BR /&gt;
quit;</description>
    <pubDate>Mon, 31 Mar 2008 04:37:13 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-03-31T04:37:13Z</dc:date>
    <item>
      <title>Simple Question on extracting rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Simple-Question-on-extracting-rows/m-p/7733#M179</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I was wondering if someone can help me with this simple problem:&lt;BR /&gt;
&lt;BR /&gt;
I have a long database that resembles the format below:&lt;BR /&gt;
Col1  Col2   Col3&lt;BR /&gt;
1.......x1........0&lt;BR /&gt;
2.......x2........0 &lt;BR /&gt;
3.......x3........0&lt;BR /&gt;
4.......x4........0&lt;BR /&gt;
5.......x5........1&lt;BR /&gt;
6.......x6........0&lt;BR /&gt;
7.......x7........0&lt;BR /&gt;
8.......x8........0&lt;BR /&gt;
&lt;BR /&gt;
I need to extract 2 rows before and after the "1" in my third column.&lt;BR /&gt;
&lt;BR /&gt;
I was thinking that I can ask SAS to do the following: When Col3 = 1  it should copy the observation from Col1 (which is 5) and create Col4 with the following variable: &lt;BR /&gt;
Col4 = Col1 - "5" . i.e: &lt;BR /&gt;
&lt;BR /&gt;
Col1  Col2   Col3 Col4 &lt;BR /&gt;
1.......x1........0......-4&lt;BR /&gt;
2.......x2........0......-3 &lt;BR /&gt;
3.......x3........0......-2&lt;BR /&gt;
4.......x4........0......-1&lt;BR /&gt;
5.......x5........1.......0&lt;BR /&gt;
6.......x6........0.......1&lt;BR /&gt;
7.......x7........0.......2&lt;BR /&gt;
8.......x8........0.......3&lt;BR /&gt;
&lt;B&gt;However I am not sure how to store "5" to use it later. Maybe i can even create another column with all "5"s. &lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
Then I can delete all observations greater and less than +2 and -2 respectively.&lt;BR /&gt;
&lt;BR /&gt;
So the final dataset would look like this:&lt;BR /&gt;
&lt;BR /&gt;
Col1  Col2   Col3 Col4 &lt;BR /&gt;
&lt;BR /&gt;
3.......x3........0......-2&lt;BR /&gt;
4.......x4........0......-1&lt;BR /&gt;
5.......x5........1.......0&lt;BR /&gt;
6.......x6........0.......1&lt;BR /&gt;
7.......x7........0.......2&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I need to repeat the procedure above several times.&lt;BR /&gt;
&lt;BR /&gt;
Thank you in advance for all your comments and any alternative suggestions!   :)

Message was edited by: am</description>
      <pubDate>Thu, 27 Mar 2008 18:18:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Simple-Question-on-extracting-rows/m-p/7733#M179</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-03-27T18:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: Simple Question on extracting rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Simple-Question-on-extracting-rows/m-p/7734#M180</link>
      <description>Hi,&lt;BR /&gt;
   I think the following code is helpful to store '5'  permanantly; &lt;BR /&gt;
  Proc sql;&lt;BR /&gt;
select(col1) into:a  from libref.datasetname where col1=5;&lt;BR /&gt;
quit;</description>
      <pubDate>Mon, 31 Mar 2008 04:37:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Simple-Question-on-extracting-rows/m-p/7734#M180</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-03-31T04:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: Simple Question on extracting rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Simple-Question-on-extracting-rows/m-p/7735#M181</link>
      <description>Thank you. &lt;BR /&gt;
&lt;BR /&gt;
I found another way to do it. &lt;BR /&gt;
&lt;BR /&gt;
Save the constant that i need (in this case =5) as a macro using the symput function. &lt;BR /&gt;
&lt;BR /&gt;
Thanks for your response again!</description>
      <pubDate>Mon, 31 Mar 2008 07:35:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Simple-Question-on-extracting-rows/m-p/7735#M181</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-03-31T07:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: Simple Question on extracting rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Simple-Question-on-extracting-rows/m-p/7736#M182</link>
      <description>I think you could create three new variables, newcol1, newcol2, newcol3.  Then, use a retain statement on newcol1, newcol2, newcol3.  Then, stuff the values of col1 - col3 into the newcol1-newcol3.  They will be retained so that the next record read will have the previous values in newcol1 - newcol3.  You can then do what you want to output whatever variables you want, based on the values of the previous record.</description>
      <pubDate>Mon, 31 Mar 2008 12:18:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Simple-Question-on-extracting-rows/m-p/7736#M182</guid>
      <dc:creator>JohnH</dc:creator>
      <dc:date>2008-03-31T12:18:07Z</dc:date>
    </item>
  </channel>
</rss>

