<?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: Retaining values across by groups in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values-across-by-groups/m-p/532793#M146021</link>
    <description>&lt;P&gt;I really struggled to get my data in a usable format but it posted in an unfriendly way.&amp;nbsp; Is there a best way to post sample data when asking for help?&lt;/P&gt;</description>
    <pubDate>Mon, 04 Feb 2019 22:23:12 GMT</pubDate>
    <dc:creator>buechler66</dc:creator>
    <dc:date>2019-02-04T22:23:12Z</dc:date>
    <item>
      <title>Retaining values across by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values-across-by-groups/m-p/532774#M146007</link>
      <description>&lt;P&gt;Hi all. I've got a tough one here.&amp;nbsp; I have the following 3 columns of data.&amp;nbsp; Here's what I need to accomplish...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Whenever a person (PERS_ID) is assigned to a new provider (PROV_ID) I need to calculate how many days have pasted from the previous appointment date (APPT_DATE) for the previous provider to the current appointment date of the new provider.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, at record 2 the PROV_ID changes for PERS_ID 134841 from&amp;nbsp;&lt;CODE class=" language-sas"&gt;1386065225 to&amp;nbsp;1235209446. So I need to calculate the days difference between&amp;nbsp;17-Aug-17 and&amp;nbsp;1-Aug-17.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;For example, at record 6 the PROV_ID changes for PERS_ID 134841 from &lt;CODE class=" language-sas"&gt;1235209446&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;to 1144621806. So I need to calculate the days difference between 16-Oct-17 and 16-Nov-17.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;I need help accomplishing this if you know a solution?&amp;nbsp; Thanks so much.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;PERS_ID PROV_ID APPT_DATE Calc_days&lt;BR /&gt;134841 1386065225 1-Aug-17&lt;BR /&gt;134841 1235209446 17-Aug-17 16&lt;BR /&gt;134841 1235209446 17-Aug-17&lt;BR /&gt;134841 1235209446 16-Oct-17&lt;BR /&gt;134841 1235209446 16-Oct-17&lt;BR /&gt;134841 1144621806 16-Nov-17 31&lt;BR /&gt;134841 1144621806 16-Nov-17&lt;BR /&gt;134841 1144621806 15-Jan-18&lt;BR /&gt;134841 1144621806 15-Jan-18&lt;BR /&gt;134841 1235209446 30-May-18 ?&lt;BR /&gt;134841 1235209446 30-May-18&lt;BR /&gt;134841 1235209446 29-Jul-18&lt;BR /&gt;134841 1235209446 29-Jul-18&lt;BR /&gt;927789 1992766273 13-Aug-17&lt;BR /&gt;927789 1992766273 13-Aug-17&lt;BR /&gt;927789 1992766273 12-Oct-17&lt;BR /&gt;927789 1992766273 12-Oct-17&lt;BR /&gt;927789 1871889956 10-Nov-17 ?&lt;BR /&gt;927789 1871889956 10-Nov-17&lt;BR /&gt;927789 1447417639 29-Nov-17 ?&lt;BR /&gt;927789 1306858121 18-Jan-18 ?&lt;BR /&gt;927789 1306858121 19-Mar-18&lt;BR /&gt;927789 1306858121 18-May-18&lt;BR /&gt;1647935 1679803183 14-Sep-17&lt;BR /&gt;1647935 1679803183 14-Sep-17&lt;BR /&gt;1647935 1477695468 16-Mar-18 ?&lt;BR /&gt;1647935 1477695468 16-Mar-18&lt;BR /&gt;1647935 1295738037 21-Jun-18 ?&lt;BR /&gt;1647935 1114984275 27-Jul-18 ?&lt;BR /&gt;1647935 1114984275 27-Jul-18&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 22:06:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values-across-by-groups/m-p/532774#M146007</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2019-02-04T22:06:20Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values across by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values-across-by-groups/m-p/532781#M146011</link>
      <description>&lt;P&gt;do you mean something like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
input PERSON_ID PROVIDER_ID APPT_DATE :date9.;
format APPT_DATE date7.;
cards;
134841 1386065225 1-Aug-17
134841 1235209446 17-Aug-17
134841 1235209446 17-Aug-17
134841 1235209446 16-Oct-17
134841 1235209446 16-Oct-17
134841 1144621806 16-Nov-17
134841 1144621806 16-Nov-17
134841 1144621806 15-Jan-18
134841 1144621806 15-Jan-18
134841 1235209446 30-May-18
134841 1235209446 30-May-18
134841 1235209446 29-Jul-18
134841 1235209446 29-Jul-18
927789 1992766273 13-Aug-17
927789 1992766273 13-Aug-17
927789 1992766273 12-Oct-17
927789 1992766273 12-Oct-17
927789 1871889956 10-Nov-17
927789 1871889956 10-Nov-17
927789 1447417639 29-Nov-17
927789 1306858121 18-Jan-18
927789 1306858121 19-Mar-18
927789 1306858121 18-May-18
1647935 1679803183 14-Sep-17
1647935 1679803183 14-Sep-17
1647935 1477695468 16-Mar-18
1647935 1477695468 16-Mar-18
1647935 1295738037 21-Jun-18
1647935 1114984275 27-Jul-18
1647935 1114984275 27-Jul-18
;

data want;
set have;
by person_id;
want=ifn( not first.person_id and lag(PROVIDER_ID) ne PROVIDER_ID , dif(APPT_DATE),.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Feb 2019 22:05:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values-across-by-groups/m-p/532781#M146011</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-04T22:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values across by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values-across-by-groups/m-p/532783#M146013</link>
      <description>&lt;P&gt;Please provide your sample data in a proper format, by providing in a data step you can expect more people responding quickly.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 22:11:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values-across-by-groups/m-p/532783#M146013</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2019-02-04T22:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values across by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values-across-by-groups/m-p/532785#M146014</link>
      <description>oh no. I thought I had. I guess I don't know the proper format. Any suggestions?</description>
      <pubDate>Mon, 04 Feb 2019 22:14:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values-across-by-groups/m-p/532785#M146014</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2019-02-04T22:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values across by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values-across-by-groups/m-p/532789#M146017</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/79805"&gt;@buechler66&lt;/a&gt;&amp;nbsp; did you not notice my solution? Please let me know whether that works or not&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 22:17:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values-across-by-groups/m-p/532789#M146017</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-04T22:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values across by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values-across-by-groups/m-p/532791#M146019</link>
      <description>Wow! How in the world did you do that so fast?! And so simply with just a few lines of code. Thank you so so much! I really appreciate it.</description>
      <pubDate>Mon, 04 Feb 2019 22:20:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values-across-by-groups/m-p/532791#M146019</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2019-02-04T22:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values across by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values-across-by-groups/m-p/532793#M146021</link>
      <description>&lt;P&gt;I really struggled to get my data in a usable format but it posted in an unfriendly way.&amp;nbsp; Is there a best way to post sample data when asking for help?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 22:23:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values-across-by-groups/m-p/532793#M146021</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2019-02-04T22:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Retaining values across by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retaining-values-across-by-groups/m-p/532797#M146024</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/79805"&gt;@buechler66&lt;/a&gt;&amp;nbsp; &amp;nbsp;Don't worry about it. All I need is something i can copy paste, which you did right. I don't care about the datastep form. It's less than 25 seconds work. Chill&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 22:27:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retaining-values-across-by-groups/m-p/532797#M146024</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-04T22:27:29Z</dc:date>
    </item>
  </channel>
</rss>

