<?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: Adding prefix to the visit based on previous or upcoming visits in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Adding-prefix-to-the-visit-based-on-previous-or-upcoming-visits/m-p/461121#M14320</link>
    <description>&lt;P&gt;sorry typo, last visit is also of the same subject 101&lt;/P&gt;</description>
    <pubDate>Wed, 09 May 2018 16:59:17 GMT</pubDate>
    <dc:creator>pavan1</dc:creator>
    <dc:date>2018-05-09T16:59:17Z</dc:date>
    <item>
      <title>Adding prefix to the visit based on previous or upcoming visits</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Adding-prefix-to-the-visit-based-on-previous-or-upcoming-visits/m-p/461120#M14319</link>
      <description>&lt;P&gt;Hello Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a typical situation here to handle.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Client gave me several visits and wanted to modify(adding prefix to unscheduled visits) the visits based on the previous or next visits, the problem here is we dont even know when the unscheduled visit comes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the snapshot of the scenario.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly, help me with this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;subject&amp;nbsp;&amp;nbsp; &amp;nbsp;visit&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;Expected Visit&lt;BR /&gt;101&amp;nbsp;&amp;nbsp; &amp;nbsp;baseline&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; baseline&lt;BR /&gt;101&amp;nbsp;&amp;nbsp; &amp;nbsp;unscheduled 01&amp;nbsp;&amp;nbsp; &amp;nbsp;MTN Unscheduled 01&lt;BR /&gt;101&amp;nbsp;&amp;nbsp; &amp;nbsp;unscheduled 02&amp;nbsp;&amp;nbsp; &amp;nbsp;MTN Unscheduled 02&lt;BR /&gt;101&amp;nbsp;&amp;nbsp; &amp;nbsp;unscheduled 03&amp;nbsp;&amp;nbsp; &amp;nbsp;MTN Unscheduled 03&lt;BR /&gt;101&amp;nbsp;&amp;nbsp; &amp;nbsp;MTN week 07&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MTN week 07&lt;BR /&gt;101&amp;nbsp;&amp;nbsp; &amp;nbsp;MTN WEEK 13&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; MTN WEEK 13&lt;BR /&gt;101&amp;nbsp;&amp;nbsp; &amp;nbsp;REI baseline&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; REI baseline&lt;BR /&gt;101&amp;nbsp;&amp;nbsp; &amp;nbsp;REI WEEK 07&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; REI WEEK 07&lt;BR /&gt;101&amp;nbsp;&amp;nbsp; &amp;nbsp;UNSCHEDULED 01&amp;nbsp;&amp;nbsp; &amp;nbsp;REI UNSCHEDULED 01&lt;BR /&gt;101&amp;nbsp;&amp;nbsp; &amp;nbsp;UNSCHEDULED 02&amp;nbsp;&amp;nbsp; &amp;nbsp;REI UNSCHEDULED 02&lt;BR /&gt;103&amp;nbsp;&amp;nbsp; &amp;nbsp;REI WEEK 13&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; REI WEEK 13&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 16:58:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Adding-prefix-to-the-visit-based-on-previous-or-upcoming-visits/m-p/461120#M14319</guid>
      <dc:creator>pavan1</dc:creator>
      <dc:date>2018-05-09T16:58:08Z</dc:date>
    </item>
    <item>
      <title>Re: Adding prefix to the visit based on previous or upcoming visits</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Adding-prefix-to-the-visit-based-on-previous-or-upcoming-visits/m-p/461121#M14320</link>
      <description>&lt;P&gt;sorry typo, last visit is also of the same subject 101&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 16:59:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Adding-prefix-to-the-visit-based-on-previous-or-upcoming-visits/m-p/461121#M14320</guid>
      <dc:creator>pavan1</dc:creator>
      <dc:date>2018-05-09T16:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: Adding prefix to the visit based on previous or upcoming visits</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Adding-prefix-to-the-visit-based-on-previous-or-upcoming-visits/m-p/461154#M14321</link>
      <description>&lt;P&gt;Well, I had to make a few assumptions about your desired logic, but here's a program that creates your desired output from your input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it helps!&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;Tom&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Inter01;
set Have;
SeqNo = _n_;
run;

data Inter02;
length ExpectedVisit $20 OldPrefix $20 CurrentPrefix $20 FirstWord $20;
retain OldPrefix;
set Inter01;
by Subject;
if first.Subject then OldPrefix = " ";
FirstWord = scan(Visit, 1);
if lowcase(FirstWord) ^= "unscheduled" &amp;amp; lowcase(FirstWord) ^= "baseline"
then do;
OldPrefix = FirstWord;
ExpectedVisit = Visit;
end;
else if CurrentPrefix = "" &amp;amp; OldPrefix ^= ""
then do;
CurrentPrefix = OldPrefix;
if lowcase(FirstWord) = "unscheduled"
then ExpectedVisit = catx(" ", CurrentPrefix, Visit);
else ExpectedVisit = Visit;
end;
drop OldPrefix;
run;

proc sort data=Inter02 out=Inter03;
by descending SeqNo;
run;

data Inter04;
length ExpectedVisit $20 OldPrefix $20 CurrentPrefix $20 FirstWord $20;
retain OldPrefix;
set Inter03;
by notsorted Subject;
if first.Subject then OldPrefix = " ";
FirstWord = scan(Visit, 1);
if lowcase(FirstWord) ^= "unscheduled" &amp;amp; lowcase(FirstWord) ^= "baseline"
then do;
OldPrefix = FirstWord;
ExpectedVisit = Visit;
end;
else if CurrentPrefix = "" &amp;amp; OldPrefix ^= ""
then do;
CurrentPrefix = OldPrefix;
if lowcase(FirstWord) = "unscheduled"
then ExpectedVisit = catx(" ", CurrentPrefix, Visit);
else ExpectedVisit = Visit;
end;
run;

proc sql noprint;
create table Want as
select Subject, Visit, ExpectedVisit
from Inter04
order by SeqNo;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 May 2018 18:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Adding-prefix-to-the-visit-based-on-previous-or-upcoming-visits/m-p/461154#M14321</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2018-05-09T18:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: Adding prefix to the visit based on previous or upcoming visits</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Adding-prefix-to-the-visit-based-on-previous-or-upcoming-visits/m-p/462610#M14371</link>
      <description>Thank you so much Tom its perfectly working...!!!!</description>
      <pubDate>Wed, 16 May 2018 09:39:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Adding-prefix-to-the-visit-based-on-previous-or-upcoming-visits/m-p/462610#M14371</guid>
      <dc:creator>pavan1</dc:creator>
      <dc:date>2018-05-16T09:39:51Z</dc:date>
    </item>
  </channel>
</rss>

