<?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: Problem printing first value using if first.variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-printing-first-value-using-if-first-variable/m-p/600436#M173560</link>
    <description>&lt;P&gt;Thank you, it's a very straightforward answer!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Oct 2019 15:52:44 GMT</pubDate>
    <dc:creator>Iona</dc:creator>
    <dc:date>2019-10-30T15:52:44Z</dc:date>
    <item>
      <title>Problem printing first value using if first.variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-printing-first-value-using-if-first-variable/m-p/599532#M173072</link>
      <description>&lt;P&gt;Hi everyone!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using the SAS sample data set called stress99.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data sasuser.stress99;
   input ID $ 1-4 Name $ 7-18 RestHR 25-26 MaxHR 32-34 RecHR 39-41
         TimeMin 48-49 TimeSec 57-58 Tolerance $ 65 Year 70-73;
datalines;
2501  Bonaventure, T    78     177    139      11       13      I    1999
2544  Jones, M          79     187    136      12       26      N    1999
2552  Reberson, P       69     158    139      15       41      D    1999
2568  Eberhardt, S      72     182    122      16       49      N    1999
2571  Nunnelly, A       65     181    141      15        2      I    1999
2578  Cameron, L        75     158    108      14       27      I    1999
2579  Underwood, K      72     165    127      13       19      S    1999
2588  Ivan, H           70     182    126      15       41      N    1999
2595  Warren, C         77     170    136      12       10      S    1999
;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now what I would like to do is to create a data set that holds only the smallest value for TimeMin, which would be TimeMin=11.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = sasuser.stress99; by timemin; run; 

data bla (drop = resthr maxhr rechr tolerance timesec year);
	set sasuser.stress99;
	by  timemin;
	first_time= first.timemin;&lt;BR /&gt;&lt;BR /&gt;        if first.timemin;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But what it will give me is the first UNIQUE value for TimeMin. Where am I going wrong?&amp;nbsp; I found &lt;A href="https://communities.sas.com/t5/SAS-Programming/Maximum-value-of-a-column-variable/td-p/28751" target="_self"&gt;this solution&lt;/A&gt; and I don't see why it works in their example but not in mine.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sat, 26 Oct 2019 14:09:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-printing-first-value-using-if-first-variable/m-p/599532#M173072</guid>
      <dc:creator>Iona</dc:creator>
      <dc:date>2019-10-26T14:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: Problem printing first value using if first.variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-printing-first-value-using-if-first-variable/m-p/599722#M173175</link>
      <description>&lt;P&gt;the way that the unprinted variable &lt;EM&gt;first.[var]&lt;/EM&gt;&amp;nbsp;works is that it will resolve to 1 for the first observation with a distinct value - so if you are conditionally setting a table by saying if first.timein it will keep the first observation with a distinct value (this is also what's happening in the other solution you linked.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if you're after the minimum value in the whole dataset, using&amp;nbsp; i would recommend turning it into a macro;&lt;/P&gt;&lt;P&gt;proc sql noprint; select min(timemin) into: mintimemin from stress99;&lt;BR /&gt;%put &amp;amp;mintimemin.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this will allow you to run calculations off this value&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 05:59:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-printing-first-value-using-if-first-variable/m-p/599722#M173175</guid>
      <dc:creator>jarg</dc:creator>
      <dc:date>2019-10-28T05:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: Problem printing first value using if first.variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-printing-first-value-using-if-first-variable/m-p/599723#M173176</link>
      <description>The link you posted is solving a different problem:  the minimum for each category.&lt;BR /&gt;&lt;BR /&gt;Try (after sorting) :&lt;BR /&gt;&lt;BR /&gt;data bla (drop = ....) ;&lt;BR /&gt;   set sasuser.stress99 (obs=1) ;&lt;BR /&gt;run;</description>
      <pubDate>Mon, 28 Oct 2019 06:13:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-printing-first-value-using-if-first-variable/m-p/599723#M173176</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-10-28T06:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: Problem printing first value using if first.variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-printing-first-value-using-if-first-variable/m-p/600435#M173559</link>
      <description>&lt;P&gt;Thank you for your answer! I was able to use it. I wasn't too clear in my question but I wanted to keep the whole observation with the minimum timemin.&lt;/P&gt;&lt;P&gt;I used your solution to write&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table subset as
select ID, Name, min(timemin) as mintime from stress;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I never used proc SQL so while it's straightforward it's still new to me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 15:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-printing-first-value-using-if-first-variable/m-p/600435#M173559</guid>
      <dc:creator>Iona</dc:creator>
      <dc:date>2019-10-30T15:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Problem printing first value using if first.variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-printing-first-value-using-if-first-variable/m-p/600436#M173560</link>
      <description>&lt;P&gt;Thank you, it's a very straightforward answer!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 15:52:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-printing-first-value-using-if-first-variable/m-p/600436#M173560</guid>
      <dc:creator>Iona</dc:creator>
      <dc:date>2019-10-30T15:52:44Z</dc:date>
    </item>
  </channel>
</rss>

