<?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 How to use .first variable in SAS data step in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-first-variable-in-SAS-data-step/m-p/73218#M21222</link>
    <description>Scenario: Want to pull only the first record of a dataset by user ID (may be duplicates for any given user) by earliest date and record number ID (may be duplicates for any given user).  This is what I’ve tried so far and it is not always pulling the first visit.&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=FirstVisit;&lt;BR /&gt;
   by UserID DATE RecordNo;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data FirstVisit;&lt;BR /&gt;
   set FirstVisit;&lt;BR /&gt;
 /*maybe I should be using a retain statement here???)  &lt;BR /&gt;
   by UserID DATE RecordNo;&lt;BR /&gt;
  /*If it was their first offer*/&lt;BR /&gt;
   if first.UserID then VisitType = 'Initial Visit';&lt;BR /&gt;
   else VisitType = 'FollowupVisit';    &lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data= FirstVisit;&lt;BR /&gt;
   by VisitType UserID;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data Visits;&lt;BR /&gt;
   set Visits;&lt;BR /&gt;
   keep UserID VisitType DATE RecordNo;&lt;BR /&gt;
   if VisitType = ‘Initial Visit';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Thanks for any suggestions re above data steps or alternative code you may be able to provide.  Much appreciated.</description>
    <pubDate>Thu, 24 Sep 2009 18:23:58 GMT</pubDate>
    <dc:creator>SASNovice</dc:creator>
    <dc:date>2009-09-24T18:23:58Z</dc:date>
    <item>
      <title>How to use .first variable in SAS data step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-first-variable-in-SAS-data-step/m-p/73218#M21222</link>
      <description>Scenario: Want to pull only the first record of a dataset by user ID (may be duplicates for any given user) by earliest date and record number ID (may be duplicates for any given user).  This is what I’ve tried so far and it is not always pulling the first visit.&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=FirstVisit;&lt;BR /&gt;
   by UserID DATE RecordNo;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data FirstVisit;&lt;BR /&gt;
   set FirstVisit;&lt;BR /&gt;
 /*maybe I should be using a retain statement here???)  &lt;BR /&gt;
   by UserID DATE RecordNo;&lt;BR /&gt;
  /*If it was their first offer*/&lt;BR /&gt;
   if first.UserID then VisitType = 'Initial Visit';&lt;BR /&gt;
   else VisitType = 'FollowupVisit';    &lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data= FirstVisit;&lt;BR /&gt;
   by VisitType UserID;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data Visits;&lt;BR /&gt;
   set Visits;&lt;BR /&gt;
   keep UserID VisitType DATE RecordNo;&lt;BR /&gt;
   if VisitType = ‘Initial Visit';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Thanks for any suggestions re above data steps or alternative code you may be able to provide.  Much appreciated.</description>
      <pubDate>Thu, 24 Sep 2009 18:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-first-variable-in-SAS-data-step/m-p/73218#M21222</guid>
      <dc:creator>SASNovice</dc:creator>
      <dc:date>2009-09-24T18:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to use .first variable in SAS data step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-first-variable-in-SAS-data-step/m-p/73219#M21223</link>
      <description>I ran your code ( after fixing open ended comments and differing dataset names) and got the first visit record every time.&lt;BR /&gt;
&lt;BR /&gt;
Are you using SAS Dates?&lt;BR /&gt;
Perhaps you could post more about your data that would point to the problem.</description>
      <pubDate>Thu, 24 Sep 2009 19:39:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-first-variable-in-SAS-data-step/m-p/73219#M21223</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-09-24T19:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to use .first variable in SAS data step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-first-variable-in-SAS-data-step/m-p/73220#M21224</link>
      <description>try this simple solution&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=FirstVisit;&lt;BR /&gt;
by UserID DATE RecordNo;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=FirstVisit NODUPKEY;&lt;BR /&gt;
by UserID;&lt;BR /&gt;
run;</description>
      <pubDate>Thu, 24 Sep 2009 20:26:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-first-variable-in-SAS-data-step/m-p/73220#M21224</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2009-09-24T20:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to use .first variable in SAS data step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-first-variable-in-SAS-data-step/m-p/73221#M21225</link>
      <description>Best to also code EQUALS with NODUPKEY - not assumed a default behavior with all sort packages.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 24 Sep 2009 20:33:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-first-variable-in-SAS-data-step/m-p/73221#M21225</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-24T20:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to use .first variable in SAS data step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-first-variable-in-SAS-data-step/m-p/73222#M21226</link>
      <description>Better to make one's logic explicit imho:&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=FirstVisit;&lt;BR /&gt;
by UserID DATE RecordNo;&lt;BR /&gt;
run;&lt;BR /&gt;
data FirstVisit &lt;BR /&gt;
  set FirstVisit ;&lt;BR /&gt;
  by UserID;&lt;BR /&gt;
  if first.UserID;&lt;BR /&gt;
run;</description>
      <pubDate>Thu, 24 Sep 2009 22:36:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-first-variable-in-SAS-data-step/m-p/73222#M21226</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-09-24T22:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to use .first variable in SAS data step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-first-variable-in-SAS-data-step/m-p/73223#M21227</link>
      <description>Well then this must be even more clear code &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
data FirstVisit; &lt;BR /&gt;
set FirstVisit ;&lt;BR /&gt;
by UserID;&lt;BR /&gt;
if first.UserID then output FirstVisit;&lt;BR /&gt;
else delete;&lt;BR /&gt;
run;</description>
      <pubDate>Fri, 25 Sep 2009 09:59:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-first-variable-in-SAS-data-step/m-p/73223#M21227</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2009-09-25T09:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to use .first variable in SAS data step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-first-variable-in-SAS-data-step/m-p/73224#M21228</link>
      <description>I have reviewed all the responses received re .first variable data step.  Haven't found a solution yet.  In your message, you said that you were sucessful in running code... to get the first record.  Would you be able to post this code for me and I'll try it in my program.&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your follow-up.&lt;BR /&gt;
&lt;BR /&gt;
P.S.  I am using SAS dates</description>
      <pubDate>Tue, 29 Sep 2009 14:20:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-first-variable-in-SAS-data-step/m-p/73224#M21228</guid>
      <dc:creator>SASNovice</dc:creator>
      <dc:date>2009-09-29T14:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to use .first variable in SAS data step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-first-variable-in-SAS-data-step/m-p/73225#M21229</link>
      <description>I want to thank all of you for replying to my post and providing suggestions - much appreciated.</description>
      <pubDate>Tue, 29 Sep 2009 14:23:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-first-variable-in-SAS-data-step/m-p/73225#M21229</guid>
      <dc:creator>SASNovice</dc:creator>
      <dc:date>2009-09-29T14:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to use .first variable in SAS data step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-first-variable-in-SAS-data-step/m-p/73226#M21230</link>
      <description>My code (as well as others') should work, unless the issue was misunderstood. &lt;BR /&gt;
Pls explain what is not right.</description>
      <pubDate>Thu, 01 Oct 2009 04:04:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-first-variable-in-SAS-data-step/m-p/73226#M21230</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-10-01T04:04:52Z</dc:date>
    </item>
  </channel>
</rss>

