<?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 Help with re coding variable - Need another set of eyes in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-with-re-coding-variable-Need-another-set-of-eyes/m-p/274363#M54727</link>
    <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;Here are the variables I am working with:&lt;/P&gt;&lt;P&gt;ID&lt;BR /&gt;Assessment Date&lt;BR /&gt;Event Date&lt;/P&gt;&lt;P&gt;I need a variable to tell me which &lt;STRONG&gt;session&lt;/STRONG&gt; that date corresponds to (&lt;EM&gt;Baseline&lt;/EM&gt;, &lt;EM&gt;Follow Up&lt;/EM&gt;, and &lt;EM&gt;Last Session).&lt;/EM&gt; &amp;nbsp;The issue is that there are cases that only have 1 session and these 1 sessions are getting lumped in with the follow up sessions. Here is what I’ve done so far.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Use the first and last function in SAS to create a FirstDate and LastDate variable using ChildID and Assessment date.&lt;/LI&gt;&lt;LI&gt;If FirstDate = AssessmentDate Then session = Baseline&lt;/LI&gt;&lt;LI&gt;If LastDate = EventDate Then session = Last Session&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; Want; set Have;&lt;/P&gt;&lt;P&gt;by ID EventDate ;&lt;/P&gt;&lt;P&gt;if first.ID then FirstDate = AssessmentDate;&lt;/P&gt;&lt;P&gt;if last.ID then LastDate = AssessmentDate;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if FirstDate = AssessmentDate then Session = &lt;STRONG&gt;1&lt;/STRONG&gt;; /*Baseline*/&lt;/P&gt;&lt;P&gt;If LastDate = AssessmentDate then Session = &lt;STRONG&gt;3&lt;/STRONG&gt;; /*Last Session*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both of the codes below lumps those with only 1 session in with the sessions that should be follow up:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if FirstDate = LastDate and AssessmentDate = EventDate = then session = &lt;STRONG&gt;4&lt;/STRONG&gt;; /*Only 1 session*/&lt;/P&gt;&lt;P&gt;if firsthospdate NE assessmentdate_HW and firsthospdate=&lt;STRONG&gt;.&lt;/STRONG&gt; and lasthospdate=&lt;STRONG&gt;.&lt;/STRONG&gt; then Session = &lt;STRONG&gt;2&lt;/STRONG&gt;; /*Follow up*/ &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated!&lt;/P&gt;</description>
    <pubDate>Wed, 01 Jun 2016 14:13:20 GMT</pubDate>
    <dc:creator>hwangnyc</dc:creator>
    <dc:date>2016-06-01T14:13:20Z</dc:date>
    <item>
      <title>Help with re coding variable - Need another set of eyes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-re-coding-variable-Need-another-set-of-eyes/m-p/274363#M54727</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;Here are the variables I am working with:&lt;/P&gt;&lt;P&gt;ID&lt;BR /&gt;Assessment Date&lt;BR /&gt;Event Date&lt;/P&gt;&lt;P&gt;I need a variable to tell me which &lt;STRONG&gt;session&lt;/STRONG&gt; that date corresponds to (&lt;EM&gt;Baseline&lt;/EM&gt;, &lt;EM&gt;Follow Up&lt;/EM&gt;, and &lt;EM&gt;Last Session).&lt;/EM&gt; &amp;nbsp;The issue is that there are cases that only have 1 session and these 1 sessions are getting lumped in with the follow up sessions. Here is what I’ve done so far.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Use the first and last function in SAS to create a FirstDate and LastDate variable using ChildID and Assessment date.&lt;/LI&gt;&lt;LI&gt;If FirstDate = AssessmentDate Then session = Baseline&lt;/LI&gt;&lt;LI&gt;If LastDate = EventDate Then session = Last Session&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; Want; set Have;&lt;/P&gt;&lt;P&gt;by ID EventDate ;&lt;/P&gt;&lt;P&gt;if first.ID then FirstDate = AssessmentDate;&lt;/P&gt;&lt;P&gt;if last.ID then LastDate = AssessmentDate;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if FirstDate = AssessmentDate then Session = &lt;STRONG&gt;1&lt;/STRONG&gt;; /*Baseline*/&lt;/P&gt;&lt;P&gt;If LastDate = AssessmentDate then Session = &lt;STRONG&gt;3&lt;/STRONG&gt;; /*Last Session*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both of the codes below lumps those with only 1 session in with the sessions that should be follow up:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if FirstDate = LastDate and AssessmentDate = EventDate = then session = &lt;STRONG&gt;4&lt;/STRONG&gt;; /*Only 1 session*/&lt;/P&gt;&lt;P&gt;if firsthospdate NE assessmentdate_HW and firsthospdate=&lt;STRONG&gt;.&lt;/STRONG&gt; and lasthospdate=&lt;STRONG&gt;.&lt;/STRONG&gt; then Session = &lt;STRONG&gt;2&lt;/STRONG&gt;; /*Follow up*/ &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2016 14:13:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-re-coding-variable-Need-another-set-of-eyes/m-p/274363#M54727</guid>
      <dc:creator>hwangnyc</dc:creator>
      <dc:date>2016-06-01T14:13:20Z</dc:date>
    </item>
    <item>
      <title>Re: Help with re coding variable - Need another set of eyes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-re-coding-variable-Need-another-set-of-eyes/m-p/274367#M54728</link>
      <description>&lt;P&gt;Look up ELSE for use with IF-Then.&lt;/P&gt;
&lt;P&gt;The ELSE part only gets assigned if the first is not true. Your code is evaluating both cases every time.&lt;/P&gt;
&lt;P&gt;And since you are using a variable LASTDATE that should only have a value when LAST.ID you only want them evaluated when LAST.ID. So consider&lt;/P&gt;
&lt;P&gt;If Last.Id then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; LastDate = AssessmentDate;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; If LastDate = AssessmentDate then Session = &lt;STRONG&gt;3&lt;/STRONG&gt;; /*Last Session*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if FirstDate = LastDate and AssessmentDate = EventDate = then session = &lt;STRONG&gt;4&lt;/STRONG&gt;; /*Only 1 session*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; else if firsthospdate NE assessmentdate_HW and firsthospdate=&lt;STRONG&gt;.&lt;/STRONG&gt; and lasthospdate=&lt;STRONG&gt;.&lt;/STRONG&gt; then Session = &lt;STRONG&gt;2&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;End;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2016 14:31:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-re-coding-variable-Need-another-set-of-eyes/m-p/274367#M54728</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-06-01T14:31:25Z</dc:date>
    </item>
  </channel>
</rss>

