<?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: How to Proc Print non-consecutive observations? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Proc-Print-non-consecutive-observations/m-p/64152#M18227</link>
    <description>Selects all rows some may be selected more than once.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
ods trace on;&lt;BR /&gt;
ods select "Extreme Observations";&lt;BR /&gt;
proc univariate data=sashelp.class;&lt;BR /&gt;
   ods output "Extreme Observations"=EXT;&lt;BR /&gt;
   run;&lt;BR /&gt;
ods trace off;&lt;BR /&gt;
data extV / view=extV;&lt;BR /&gt;
   set ext;&lt;BR /&gt;
   do point=lowobs,highobs;&lt;BR /&gt;
      set sashelp.class point=point;&lt;BR /&gt;
      _obs_ = point;&lt;BR /&gt;
      output;&lt;BR /&gt;
      end;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
    <pubDate>Sat, 14 Aug 2010 18:12:18 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2010-08-14T18:12:18Z</dc:date>
    <item>
      <title>How to Proc Print non-consecutive observations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Proc-Print-non-consecutive-observations/m-p/64151#M18226</link>
      <description>Greetings:&lt;BR /&gt;
Just learned how to use Proc Univariate to see which observations have extreme values. The next step would be to actually take a look at those obs.&lt;BR /&gt;
&lt;BR /&gt;
How do I say “proc print not the whole dataset but only a specific list of observations: e.g. where observation numbers in (1,2,5)”?&lt;BR /&gt;
&lt;BR /&gt;
Tried to find an answer online but failed. My clumsy alternative now is to use a data step to select the observations (using _n_ as a way to select the observations) then proc print this new dataset. See example below.&lt;BR /&gt;
&lt;BR /&gt;
Data ob2Select;&lt;BR /&gt;
      set obtest;&lt;BR /&gt;
      where _n_ in (1 2 5);&lt;BR /&gt;
Run;&lt;BR /&gt;
proc print data=ob2select;&lt;BR /&gt;
Run;</description>
      <pubDate>Sat, 14 Aug 2010 16:41:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Proc-Print-non-consecutive-observations/m-p/64151#M18226</guid>
      <dc:creator>mnew</dc:creator>
      <dc:date>2010-08-14T16:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to Proc Print non-consecutive observations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Proc-Print-non-consecutive-observations/m-p/64152#M18227</link>
      <description>Selects all rows some may be selected more than once.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
ods trace on;&lt;BR /&gt;
ods select "Extreme Observations";&lt;BR /&gt;
proc univariate data=sashelp.class;&lt;BR /&gt;
   ods output "Extreme Observations"=EXT;&lt;BR /&gt;
   run;&lt;BR /&gt;
ods trace off;&lt;BR /&gt;
data extV / view=extV;&lt;BR /&gt;
   set ext;&lt;BR /&gt;
   do point=lowobs,highobs;&lt;BR /&gt;
      set sashelp.class point=point;&lt;BR /&gt;
      _obs_ = point;&lt;BR /&gt;
      output;&lt;BR /&gt;
      end;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Sat, 14 Aug 2010 18:12:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Proc-Print-non-consecutive-observations/m-p/64152#M18227</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-08-14T18:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to Proc Print non-consecutive observations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Proc-Print-non-consecutive-observations/m-p/64153#M18228</link>
      <description>Thank you. Interesting solution. Will file this one to study more later (a bit over my level now). Wish there is a simple way to select by obs numbers directly in proc print...</description>
      <pubDate>Sat, 14 Aug 2010 22:49:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Proc-Print-non-consecutive-observations/m-p/64153#M18228</guid>
      <dc:creator>mnew</dc:creator>
      <dc:date>2010-08-14T22:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to Proc Print non-consecutive observations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Proc-Print-non-consecutive-observations/m-p/64154#M18229</link>
      <description>Directly?  I don't think so.  Plus, I don't think you can capture _n_ directly with a where statement.&lt;BR /&gt;
&lt;BR /&gt;
Indirectly, you could write and then repeatedly call a small macro that does what your original workaround was intended to do.  For example:&lt;BR /&gt;
&lt;BR /&gt;
%macro procprnt (filename,criteria);&lt;BR /&gt;
  data _forprint;&lt;BR /&gt;
    set &amp;amp;filename.;&lt;BR /&gt;
    if &amp;amp;criteria.;&lt;BR /&gt;
  run;&lt;BR /&gt;
&lt;BR /&gt;
  proc print data=_forprint;&lt;BR /&gt;
  run;&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
%procprnt(sashelp.class,_n_ in (1 3 5 7))</description>
      <pubDate>Sun, 15 Aug 2010 14:05:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Proc-Print-non-consecutive-observations/m-p/64154#M18229</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2010-08-15T14:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to Proc Print non-consecutive observations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Proc-Print-non-consecutive-observations/m-p/64155#M18230</link>
      <description>Reply to OP: As shown by data _null_ with his example, essentially you have the opportunity to use "observation_number" when generating a SAS VIEW from your original input file based on your data selection criteria.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
data class / view=class;&lt;BR /&gt;
  set sashelp.class;&lt;BR /&gt;
  * optionally, some WHERE condition goes here. ;&lt;BR /&gt;
  obsnum = _n_;&lt;BR /&gt;
  run;&lt;BR /&gt;
proc print u data=class;&lt;BR /&gt;
  where obsnum in (1,5,7,10);&lt;BR /&gt;
   run;</description>
      <pubDate>Sun, 15 Aug 2010 16:27:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Proc-Print-non-consecutive-observations/m-p/64155#M18230</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-08-15T16:27:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to Proc Print non-consecutive observations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Proc-Print-non-consecutive-observations/m-p/64156#M18231</link>
      <description>SET statement allows direct access by observation number to data in base sas  libraries, so&lt;BR /&gt;
data the_parts ;&lt;BR /&gt;
 do obs_wanted  = 1,3,5,9   ;&lt;BR /&gt;
    set yourlib.data_set point= obs_wanted ;&lt;BR /&gt;
    output ;&lt;BR /&gt;
 end &lt;BR /&gt;
 stop ; *&amp;lt;-------&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; inportant;&lt;BR /&gt;
run ;&lt;BR /&gt;
 proc print ;&lt;BR /&gt;
run ;</description>
      <pubDate>Sun, 15 Aug 2010 22:36:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Proc-Print-non-consecutive-observations/m-p/64156#M18231</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-08-15T22:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to Proc Print non-consecutive observations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Proc-Print-non-consecutive-observations/m-p/64157#M18232</link>
      <description>Thanks to all of you! I really did not expect anyone spending a Sunday moment to address my beginner question :-). Now I’m feeling less miserable about having to learn SAS in my spare time.</description>
      <pubDate>Mon, 16 Aug 2010 04:22:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Proc-Print-non-consecutive-observations/m-p/64157#M18232</guid>
      <dc:creator>mnew</dc:creator>
      <dc:date>2010-08-16T04:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to Proc Print non-consecutive observations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Proc-Print-non-consecutive-observations/m-p/64158#M18233</link>
      <description>We are all learning.&lt;BR /&gt;
A variation on the UNIVARIATE extremes can be obtained with the IDGROUP option in SUMMARY.  The resulting data set looks much like the one obtained through ODS and UNIVARIATE.  The DATA step then transposes it.  &lt;BR /&gt;
[pre]proc summary data=sashelp.class;&lt;BR /&gt;
var height;&lt;BR /&gt;
output out=max5&lt;BR /&gt;
       idgroup(max(height) obs out[5] (name sex age height)=)/autoname;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data fiveobs(keep=obsnum name sex age height);&lt;BR /&gt;
   set max5;&lt;BR /&gt;
   array Aobs  {5} _obs_:;&lt;BR /&gt;
   array Aname {5} name:;&lt;BR /&gt;
   array Asex  {5} sex:;&lt;BR /&gt;
   array Aage  {5} age:;&lt;BR /&gt;
   array Ahght {5} height:;&lt;BR /&gt;
   do i = 1 to 5;&lt;BR /&gt;
      obsnum=aobs{i};&lt;BR /&gt;
      name = aname{i};&lt;BR /&gt;
      sex  = asex{i};&lt;BR /&gt;
      age  = aage{i};&lt;BR /&gt;
      height=ahght{i};&lt;BR /&gt;
      output fiveobs;&lt;BR /&gt;
   end;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=fiveobs;&lt;BR /&gt;
run;[/pre]</description>
      <pubDate>Mon, 16 Aug 2010 04:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Proc-Print-non-consecutive-observations/m-p/64158#M18233</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-08-16T04:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to Proc Print non-consecutive observations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Proc-Print-non-consecutive-observations/m-p/64159#M18234</link>
      <description>Tried this. Neat. Can't wait to learn SAS arrays (4 lessons away)!&lt;BR /&gt;
Thank you for sharing the tip and the encouragement!</description>
      <pubDate>Tue, 17 Aug 2010 03:35:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Proc-Print-non-consecutive-observations/m-p/64159#M18234</guid>
      <dc:creator>mnew</dc:creator>
      <dc:date>2010-08-17T03:35:16Z</dc:date>
    </item>
  </channel>
</rss>

