<?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: IF/THEN question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-question/m-p/458839#M116467</link>
    <description>&lt;P&gt;Figure it out!!!! The below code uses the Lag() function which looks back at the previous observation. As long at the patient_ID is the same for the current observation and the previous observation it works for determining if the patient has been receiving care over the course of at least two visits.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The ONLY issue that I have with this is that, I want to be able to look at ALL lad dates for one patient a determine what i need by looking at the observations in the by group together. This ONLY allows me to visit the previous observations. So it works but its not as efficient as I want.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set sample;&lt;BR /&gt;by by_group;

if last.by_group and collection_date &amp;gt; '01jan2017'd &lt;BR /&gt;then linked=1;

if last.by_group and lag(by_group)=by_group &lt;BR /&gt;and collection_date &amp;gt; '01jan2017'd &lt;BR /&gt;and collection_date-lag(collection_date)&amp;lt;365&lt;BR /&gt;then retained=1;								&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 30 Apr 2018 20:41:50 GMT</pubDate>
    <dc:creator>rcleven2</dc:creator>
    <dc:date>2018-04-30T20:41:50Z</dc:date>
    <item>
      <title>IF/THEN question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-question/m-p/458754#M116442</link>
      <description>&lt;P&gt;Straight forward problem that I am just not sure how to structure in the code. I have several patients with labs in a dataset. Each Obs is a a lab collected on a different date. The issue is that I am trying to distinguish if a person in Linked to care (only 1 lab) or if they have been retained in care (more than 1 lab within 1 year of today). I am wanting to create a Linked and retained variable&amp;nbsp; with 1 meaning True and . meaning false. Eventually I will be deleting all observations that are not last.name. How can I use an IF/THEN or IF/THEN DO statement to use historical observations to&amp;nbsp; dictate values on the current line?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;lab_date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; result&amp;nbsp; &amp;nbsp; &amp;nbsp; DESIRED&amp;gt;&amp;gt;&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Linked&amp;nbsp; &amp;nbsp; Retained&lt;/P&gt;&lt;P&gt;bob&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01/01/2016&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;400&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;bob&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 06/15/2016&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 400&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;bob&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 06/01/2017&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;400&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;bob&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12/31/2017&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;400&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;1&amp;nbsp; &amp;nbsp;/*Multiple visits within the 365 days*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;craig&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01/01/2015&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;400&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;craig&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02/09/2018 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 400&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp;/*Only one visit within 365 days*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;steve&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/01/2015&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;400&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp;/*No visits within&amp;nbsp; timeframe*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;bob&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01/21/2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;400&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp;/*Only one visit within 365 days*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Apr 2018 17:32:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-question/m-p/458754#M116442</guid>
      <dc:creator>rcleven2</dc:creator>
      <dc:date>2018-04-30T17:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-question/m-p/458756#M116444</link>
      <description>&lt;P&gt;is this if then question or interval check?&lt;/P&gt;</description>
      <pubDate>Mon, 30 Apr 2018 17:35:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-question/m-p/458756#M116444</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-30T17:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-question/m-p/458760#M116445</link>
      <description>&lt;P&gt;Im not sure what an "Interval check" is and I had fully intended on using If then statements to produce the output I want. That is unless someone can show me a different way to accomplish this. If you can feel free to share, that is why I am here.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Apr 2018 17:39:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-question/m-p/458760#M116445</guid>
      <dc:creator>rcleven2</dc:creator>
      <dc:date>2018-04-30T17:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-question/m-p/458761#M116446</link>
      <description>&lt;P&gt;Ok no worries, please post a sample of your HAVE(input dataset) and WANT(expected output) and the logic. Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDITED: I think my assumption is right and understand what you want. Sorry your title confused me&lt;/P&gt;</description>
      <pubDate>Mon, 30 Apr 2018 17:43:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-question/m-p/458761#M116446</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-30T17:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-question/m-p/458775#M116448</link>
      <description>&lt;P&gt;Here is a sample of what I am working with. I created the variables linked and retained. They just need to be filled in as mentioned in the original post. The end goal is to have a set with one observation per patient that would look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(*collection_date viral_load and provider&amp;nbsp;and other variables will most likely be deleted from data sets moving forward)&lt;/P&gt;&lt;P&gt;last&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.........&amp;nbsp; &amp;nbsp;collection_date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;viral_load&amp;nbsp; &amp;nbsp; &amp;nbsp;provider&amp;nbsp; &amp;nbsp; &amp;nbsp; linked&amp;nbsp; &amp;nbsp; &amp;nbsp; retained&lt;/P&gt;&lt;P&gt;bob&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/01/2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 200&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; other&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;bill&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;05/16/2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; other&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;bret&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08/21/2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 78&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; other&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;bacon&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/01/2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 563&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; other&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Apr 2018 18:06:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-question/m-p/458775#M116448</guid>
      <dc:creator>rcleven2</dc:creator>
      <dc:date>2018-04-30T18:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-question/m-p/458777#M116450</link>
      <description>&lt;P&gt;Oh my god, are you asking for like?--if yes my bad and sincere apologies&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by name;
if last.name;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or perhaps i am not understanding this part of what you wrote--"&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;"How can I use an IF/THEN or IF/THEN DO statement to use historical observations to&amp;nbsp; dictate values on the current line?"&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Apr 2018 18:13:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-question/m-p/458777#M116450</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-30T18:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-question/m-p/458780#M116451</link>
      <description>&lt;P&gt;Yes, that is process that I believe that it will take. That is ok. I will continue to play around with it. If/When i figure it out I will post the solution.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Apr 2018 18:21:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-question/m-p/458780#M116451</guid>
      <dc:creator>rcleven2</dc:creator>
      <dc:date>2018-04-30T18:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-question/m-p/458839#M116467</link>
      <description>&lt;P&gt;Figure it out!!!! The below code uses the Lag() function which looks back at the previous observation. As long at the patient_ID is the same for the current observation and the previous observation it works for determining if the patient has been receiving care over the course of at least two visits.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The ONLY issue that I have with this is that, I want to be able to look at ALL lad dates for one patient a determine what i need by looking at the observations in the by group together. This ONLY allows me to visit the previous observations. So it works but its not as efficient as I want.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set sample;&lt;BR /&gt;by by_group;

if last.by_group and collection_date &amp;gt; '01jan2017'd &lt;BR /&gt;then linked=1;

if last.by_group and lag(by_group)=by_group &lt;BR /&gt;and collection_date &amp;gt; '01jan2017'd &lt;BR /&gt;and collection_date-lag(collection_date)&amp;lt;365&lt;BR /&gt;then retained=1;								&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Apr 2018 20:41:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-question/m-p/458839#M116467</guid>
      <dc:creator>rcleven2</dc:creator>
      <dc:date>2018-04-30T20:41:50Z</dc:date>
    </item>
  </channel>
</rss>

