<?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 status changes over time in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/status-changes-over-time/m-p/473646#M121565</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I have the following input data set .&lt;/P&gt;&lt;P&gt;Each customer ID has follow up fields of 12 months.&lt;/P&gt;&lt;P&gt;First Field is Status1701 &amp;nbsp;and &amp;nbsp;all customers are in status 0 in 1701 (Jan 2017) .&lt;/P&gt;&lt;P&gt;Status 0 means that customer is active in my department.&lt;/P&gt;&lt;P&gt;There are 2 more possible status levels:&lt;/P&gt;&lt;P&gt;status1- customer left the company&lt;/P&gt;&lt;P&gt;status2-customer left the department but is still in company.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The task is to find the status changes for each customer&lt;/P&gt;&lt;P&gt;This should be the desired calculated field "&lt;SPAN&gt;Conclusion"&lt;/SPAN&gt;:&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; Conclusion&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; Alway 0&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 to 1 to 0&lt;BR /&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; o to 1&lt;BR /&gt;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; o to 1&lt;BR /&gt;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 to 2&lt;BR /&gt;6 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 to 1 to 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data tbl1;&lt;BR /&gt;input ID Status1701 Status1702 Status1703 Status1704 Status1705 Status1706&lt;BR /&gt;Status1707 Status1708 Status1709 Status1710 Status1711 Status1712;&lt;BR /&gt;cards;&lt;BR /&gt;1 0 0 0 0 0 0 0 0 0 0 0 0&lt;BR /&gt;2 0 0 0 0 0 0 1 1 1 1 1 0&lt;BR /&gt;3 0 1 1 1 1 1 1 1 1 1 1 1&lt;BR /&gt;4 0 0 0 0 0 0 0 0 0 0 1 1&lt;BR /&gt;5 0 0 0 2 2 2 2 2 2 2 2 2&lt;BR /&gt;6 0 0 0 0 0 0 0 0 2 2 1 1&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone explain how to calculate "&lt;SPAN&gt;Conclusion" field in SAS?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;We need to find out the status changes from one status to another status&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Joey&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Jun 2018 10:12:20 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2018-06-27T10:12:20Z</dc:date>
    <item>
      <title>status changes over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/status-changes-over-time/m-p/473646#M121565</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I have the following input data set .&lt;/P&gt;&lt;P&gt;Each customer ID has follow up fields of 12 months.&lt;/P&gt;&lt;P&gt;First Field is Status1701 &amp;nbsp;and &amp;nbsp;all customers are in status 0 in 1701 (Jan 2017) .&lt;/P&gt;&lt;P&gt;Status 0 means that customer is active in my department.&lt;/P&gt;&lt;P&gt;There are 2 more possible status levels:&lt;/P&gt;&lt;P&gt;status1- customer left the company&lt;/P&gt;&lt;P&gt;status2-customer left the department but is still in company.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The task is to find the status changes for each customer&lt;/P&gt;&lt;P&gt;This should be the desired calculated field "&lt;SPAN&gt;Conclusion"&lt;/SPAN&gt;:&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; Conclusion&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; Alway 0&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 to 1 to 0&lt;BR /&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; o to 1&lt;BR /&gt;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; o to 1&lt;BR /&gt;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 to 2&lt;BR /&gt;6 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 to 1 to 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data tbl1;&lt;BR /&gt;input ID Status1701 Status1702 Status1703 Status1704 Status1705 Status1706&lt;BR /&gt;Status1707 Status1708 Status1709 Status1710 Status1711 Status1712;&lt;BR /&gt;cards;&lt;BR /&gt;1 0 0 0 0 0 0 0 0 0 0 0 0&lt;BR /&gt;2 0 0 0 0 0 0 1 1 1 1 1 0&lt;BR /&gt;3 0 1 1 1 1 1 1 1 1 1 1 1&lt;BR /&gt;4 0 0 0 0 0 0 0 0 0 0 1 1&lt;BR /&gt;5 0 0 0 2 2 2 2 2 2 2 2 2&lt;BR /&gt;6 0 0 0 0 0 0 0 0 2 2 1 1&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone explain how to calculate "&lt;SPAN&gt;Conclusion" field in SAS?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;We need to find out the status changes from one status to another status&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Joey&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 10:12:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/status-changes-over-time/m-p/473646#M121565</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-06-27T10:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: status changes over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/status-changes-over-time/m-p/473648#M121566</link>
      <description>&lt;P&gt;Right, this gets you the changes per appearance in the data - note how I use a code window which is the {i} above post area to show code:&lt;/P&gt;
&lt;PRE&gt;data tbl1;
  input ID Status1701 Status1702 Status1703 Status1704 Status1705 Status1706
           Status1707 Status1708 Status1709 Status1710 Status1711 Status1712;
cards;
1 0 0 0 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 1 1 1 1 1 0
3 0 1 1 1 1 1 1 1 1 1 1 1
4 0 0 0 0 0 0 0 0 0 0 1 1
5 0 0 0 2 2 2 2 2 2 2 2 2
6 0 0 0 0 0 0 0 0 2 2 1 1
;
run;

data want;
  set tbl1;
  length changes $20;
  array x{12} status1701--status1712;
  changes=strip(put(x{1},best.));
  curr=x{1};
  do i=2 to 12;
    if x{i} ne curr then do;
      curr=x{i};
      changes=catx(',',changes,strip(put(x{i},best.)));
    end;    
  end;
  changes=tranwrd(changes,","," to ");
run;&lt;/PRE&gt;
&lt;P&gt;Note, your want in your post is incorrect, you say:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;6 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 to 1 to 2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Which does not match the data which is 0-2-1&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 10:25:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/status-changes-over-time/m-p/473648#M121566</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-27T10:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: status changes over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/status-changes-over-time/m-p/473680#M121577</link>
      <description>&lt;P&gt;Thank you so much!&lt;/P&gt;&lt;P&gt;It is a very clever and nice solution.&lt;/P&gt;&lt;P&gt;May I ask please:&lt;/P&gt;&lt;PRE&gt;strip(put(x{1},best.))&lt;BR /&gt;What is the reason of using strip function here?&lt;BR /&gt;What is the purpose of using best. format?&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Jun 2018 12:13:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/status-changes-over-time/m-p/473680#M121577</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-06-27T12:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: status changes over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/status-changes-over-time/m-p/473685#M121580</link>
      <description>&lt;P&gt;I use the best here just because I was being lazy, basically its a catch all for numeric formats.&amp;nbsp; And because I was lazy I then had to wrap a strip() function to remove any blanks that may have been added, for instance if the best format takes 8. then there would be 7 blanks.&amp;nbsp; If I wasn't being lazy I would look at my data and see it is all 1 number in length, so to acurately write this:&lt;/P&gt;
&lt;PRE&gt;data tbl1;
  input ID Status1701 Status1702 Status1703 Status1704 Status1705 Status1706
           Status1707 Status1708 Status1709 Status1710 Status1711 Status1712;
cards;
1 0 0 0 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 1 1 1 1 1 0
3 0 1 1 1 1 1 1 1 1 1 1 1
4 0 0 0 0 0 0 0 0 0 0 1 1
5 0 0 0 2 2 2 2 2 2 2 2 2
6 0 0 0 0 0 0 0 0 2 2 1 1
;
run;

data want;
  set tbl1;
  length changes $24;
  array x{12} status1701--status1712;
  changes=put(x{1},1.);
  curr=x{1};
  do i=2 to 12;
    if x{i} ne curr then do;
      curr=x{i};
      changes=catx(',',changes,put(x{i},1.));
    end;    
  end;
  changes=tranwrd(changes,","," to ");
run;&lt;/PRE&gt;
&lt;P&gt;Goes to show you can write code which works, but isn't optimal.&amp;nbsp; I also changed the length on changes as possibly 12 values with 11 commas.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 12:21:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/status-changes-over-time/m-p/473685#M121580</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-27T12:21:20Z</dc:date>
    </item>
    <item>
      <title>Re: status changes over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/status-changes-over-time/m-p/473965#M121706</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tbl1;
  input ID Status1701 Status1702 Status1703 Status1704 Status1705 Status1706
           Status1707 Status1708 Status1709 Status1710 Status1711 Status1712;
cards;
1 0 0 0 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 1 1 1 1 1 0
3 0 1 1 1 1 1 1 1 1 1 1 1
4 0 0 0 0 0 0 0 0 0 0 1 1
5 0 0 0 2 2 2 2 2 2 2 2 2
6 0 0 0 0 0 0 0 0 2 2 1 1
;
run;
proc transpose data=tbl1 out=temp;
by id;
run;
data temp1;
 set temp;
 by id col1 notsorted;
 if first.col1;
 drop _name_;
run;
data want;
 length conclusion $ 200;
 do until(last.id);
  set temp1;
  by id;
  conclusion=catx(' to ',conclusion,col1);
 end;
 drop col1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jun 2018 03:46:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/status-changes-over-time/m-p/473965#M121706</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-06-28T03:46:09Z</dc:date>
    </item>
  </channel>
</rss>

