<?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: Using Subsets in Proc Print in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Subsets-in-Proc-Print/m-p/345989#M79692</link>
    <description>&lt;P&gt;And SQL without a CREATE TABLE somewhat functions as a PRINT procedure as well.&lt;/P&gt;
&lt;P&gt;Note that in the first case there are ties - there are two people with the smallest value. The sort methodology would not account for ties.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
*Youngest age - note that there are ties here! How would you want to handle that;
title 'Youngest person - note ties';
select *
from sashelp.class
having age=min(age);
quit;

proc sql;
title 'Oldest person - no ties';
select * from sashelp.class
having age=max(age);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 30 Mar 2017 22:53:12 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-03-30T22:53:12Z</dc:date>
    <item>
      <title>Using Subsets in Proc Print</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Subsets-in-Proc-Print/m-p/345984#M79687</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to SAS programming and am wondering if there is a better way to subset my output in the print procedure. I am trying to print the oldest and youngest observations in my data set based on the variable "DOB". Below I have tried using proc sort and proc print seperately to create my output. My question is this: Is there a more efficient way to select specific observations&amp;nbsp;in the print procedure, or print a subset data based on a condition?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data = sds.school out = work.sorted_youngest ;&lt;BR /&gt;by descending DOB ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc print data = work.sorted_youngest (obs=1) noobs ;&lt;BR /&gt;var ssn gender type ethnic;&lt;BR /&gt;title 'Youngest Student in Data Set';&lt;BR /&gt;run ;&lt;/P&gt;&lt;P&gt;******************************************************&lt;/P&gt;&lt;P&gt;I do the exact same steps below, but without the 'descending' option.&lt;/P&gt;&lt;P&gt;******************************************************;&amp;nbsp;&lt;BR /&gt;proc sort data = Fitch.ProjectData out = work.sorted_oldest ;&lt;BR /&gt;by TOT_DOB ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc print data = work.sorted_oldest (obs=1) noobs;&lt;BR /&gt;var SSN SEX TYPE ETHNIC ;&lt;BR /&gt;title 'Oldest Student in Data Set' ;&lt;BR /&gt;run;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for the help!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2017 22:22:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Subsets-in-Proc-Print/m-p/345984#M79687</guid>
      <dc:creator>Proc_Help</dc:creator>
      <dc:date>2017-03-30T22:22:37Z</dc:date>
    </item>
    <item>
      <title>Re: Using Subsets in Proc Print</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Subsets-in-Proc-Print/m-p/345986#M79689</link>
      <description>&lt;P&gt;With small data sets, it doesn't matter. &amp;nbsp;Learn as you go, and anything that gets the right answer is OK. &amp;nbsp;However ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case, you're not getting the right answer. &amp;nbsp;When you sort your data (using DESCENDING), the first observation is actually the oldest, not the youngest. &amp;nbsp;That's easy to fix ... just a matter of re-labeling the results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With larger data sets, sorting can be expensive. &amp;nbsp;This would be a way to get both the youngest and the oldest in one step, sorting only once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;proc sort data = sds.school;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;by DOB ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data youngest oldest;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;set sds.school end=done;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if _n_=1 then output youngest;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if done then output oldest;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You could then print each data set separately.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Now if you are going to step it up a level beyond that, the DATA step could become:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data youngest oldest;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;set sds.school nobs=_nobs_;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;output youngest;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;set sds.school point=_nobs_;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;output oldest;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;stop;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;That avoids reading all the observations in the middle of the data set, but it's getting into heavier programming techniques. &amp;nbsp;It's better to start with the earlier steps, and fully understand how they work. &amp;nbsp;The techniques there will be more widely applicable, while the last program would be needed infrequently.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2017 22:41:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Subsets-in-Proc-Print/m-p/345986#M79689</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-30T22:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using Subsets in Proc Print</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Subsets-in-Proc-Print/m-p/345989#M79692</link>
      <description>&lt;P&gt;And SQL without a CREATE TABLE somewhat functions as a PRINT procedure as well.&lt;/P&gt;
&lt;P&gt;Note that in the first case there are ties - there are two people with the smallest value. The sort methodology would not account for ties.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
*Youngest age - note that there are ties here! How would you want to handle that;
title 'Youngest person - note ties';
select *
from sashelp.class
having age=min(age);
quit;

proc sql;
title 'Oldest person - no ties';
select * from sashelp.class
having age=max(age);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Mar 2017 22:53:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Subsets-in-Proc-Print/m-p/345989#M79692</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-30T22:53:12Z</dc:date>
    </item>
  </channel>
</rss>

