<?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: Assignments of visits based on date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assignments-of-visits-based-on-date/m-p/478545#M123408</link>
    <description>&lt;P&gt;It can be done like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=b; by id date_st date_ed; run;

data want;
length visit $10;
nn = 0;
do until (last.id);
    merge a b; by id;
    nn = nn - (coalesce(date_st, date_ed) &amp;lt; date);
    end;
do until (last.id);
    merge a b; by id;
    if coalesce(date_st, date_ed) = date then nn = 0;
    visit = cats("Visit", nn);
    output;
    nn = nn + 1;
    if nn = 0 then nn = 1; /* Skip visit0 if date is not found */
    end;
drop nn;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 17 Jul 2018 03:40:45 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2018-07-17T03:40:45Z</dc:date>
    <item>
      <title>Assignments of visits based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assignments-of-visits-based-on-date/m-p/478396#M123379</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I’m trying to assign visit names based on the&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dates. Need help regarding logic. Using SAS 9.3.&lt;/P&gt;
&lt;P&gt;i have dataset a, one record per member.&lt;/P&gt;
&lt;P&gt;id &amp;nbsp; &amp;nbsp; Date&lt;/P&gt;
&lt;P&gt;001 &amp;nbsp;28jan2016&lt;/P&gt;
&lt;P&gt;002 &amp;nbsp; 04feb2017&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dataset b: multiple records per member.need to derive&lt;/P&gt;
&lt;P&gt;visit value based on dataset a date value. Date-st is&lt;/P&gt;
&lt;P&gt;before the date then visit values should be visit-1,visit-2&lt;/P&gt;
&lt;P&gt;Etc...if Date-st is after the Date then visit values should be&amp;nbsp;&lt;/P&gt;
&lt;P&gt;visit+1 , visit+2 etc. Different number of visits per subject&lt;/P&gt;
&lt;P&gt;. If Date-st is missing then need to use Date-ed to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;assign visit.&lt;/P&gt;
&lt;P&gt;id &amp;nbsp; &amp;nbsp; &amp;nbsp;Date-st &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Date-ed &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Visit&lt;/P&gt;
&lt;P&gt;001 &amp;nbsp; 27jan2016 &amp;nbsp; &amp;nbsp;29jan2017 &amp;nbsp; &amp;nbsp;Visit-1&lt;/P&gt;
&lt;P&gt;001 &amp;nbsp; &amp;nbsp;28jan2016 &amp;nbsp; 29jan2017 &amp;nbsp; &amp;nbsp;Visit0&lt;/P&gt;
&lt;P&gt;001 &amp;nbsp; 29jan2016 &amp;nbsp; &amp;nbsp;30jan2017 &amp;nbsp; &amp;nbsp;Visit+1&lt;/P&gt;
&lt;P&gt;002 &amp;nbsp; &amp;nbsp;4feb2017 &amp;nbsp; &amp;nbsp; 6feb2017 &amp;nbsp; &amp;nbsp;Visit0&lt;/P&gt;
&lt;P&gt;002. &amp;nbsp; 6feb2017 &amp;nbsp; &amp;nbsp;7feb2017 &amp;nbsp; &amp;nbsp; &amp;nbsp;Visit1&lt;/P&gt;
&lt;P&gt;002 &amp;nbsp; &amp;nbsp;8feb2017 &amp;nbsp; &amp;nbsp;9feb2017 &amp;nbsp; &amp;nbsp; &amp;nbsp;Visit2&lt;/P&gt;
&lt;P&gt;003 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10feb2017 &amp;nbsp; &amp;nbsp; &amp;nbsp;Visit3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As I just started on SAS, Need help me with the coding.thanks for your help. &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advane.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jul 2018 15:28:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assignments-of-visits-based-on-date/m-p/478396#M123379</guid>
      <dc:creator>sasg</dc:creator>
      <dc:date>2018-07-16T15:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: Assignments of visits based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assignments-of-visits-based-on-date/m-p/478417#M123386</link>
      <description>&lt;P&gt;Is there any real reason to include "visit" in the variable if the text is in every single value?&lt;/P&gt;
&lt;P&gt;Also please confirm that your dates as SAS date valued numeric variables with a SAS date9. format applied.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you have made things somewhat difficult by not giving us the names of the datasets and&amp;nbsp;using variable names that by default are not valid for SAS variables (date-st date-ed, hyphens aren't normally valid SAS variables).&lt;/P&gt;
&lt;P&gt;Also for id 002 you compare 04feb2017 with&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jul 2018 16:44:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assignments-of-visits-based-on-date/m-p/478417#M123386</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-16T16:44:18Z</dc:date>
    </item>
    <item>
      <title>Re: Assignments of visits based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assignments-of-visits-based-on-date/m-p/478531#M123403</link>
      <description />
      <pubDate>Tue, 17 Jul 2018 02:02:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assignments-of-visits-based-on-date/m-p/478531#M123403</guid>
      <dc:creator>sasg</dc:creator>
      <dc:date>2018-07-17T02:02:19Z</dc:date>
    </item>
    <item>
      <title>Re: Assignments of visits based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assignments-of-visits-based-on-date/m-p/478545#M123408</link>
      <description>&lt;P&gt;It can be done like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=b; by id date_st date_ed; run;

data want;
length visit $10;
nn = 0;
do until (last.id);
    merge a b; by id;
    nn = nn - (coalesce(date_st, date_ed) &amp;lt; date);
    end;
do until (last.id);
    merge a b; by id;
    if coalesce(date_st, date_ed) = date then nn = 0;
    visit = cats("Visit", nn);
    output;
    nn = nn + 1;
    if nn = 0 then nn = 1; /* Skip visit0 if date is not found */
    end;
drop nn;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Jul 2018 03:40:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assignments-of-visits-based-on-date/m-p/478545#M123408</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-07-17T03:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: Assignments of visits based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assignments-of-visits-based-on-date/m-p/478809#M123502</link>
      <description>Thanks for your reply.</description>
      <pubDate>Tue, 17 Jul 2018 20:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assignments-of-visits-based-on-date/m-p/478809#M123502</guid>
      <dc:creator>sasg</dc:creator>
      <dc:date>2018-07-17T20:06:56Z</dc:date>
    </item>
  </channel>
</rss>

