<?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: Registre SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Registre-SAS/m-p/847546#M335084</link>
    <description>&lt;P&gt;Please post your example data as a data step, e.g. like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length Patient_id $1;
  informat Treatment_date mmddyy10.; 
  format Treatment_date mmddyy10.;  
  input Patient_id Treatment_date;
cards;
A 1/1/2020  
A 1/1/2020  
A 5/1/2022  
B 1/12/2021  
C 1/25/2020  
C 6/1t/2021  
D 12/31/2021  
D 12/31/2021  
D 5/25/2022  
D 7/10/2022  
D 7/10/2022  
D 10/4/2022  
;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I guess (you did not describe the result you wanted, just showed the example) the calculation you want can be done like this (data must be sorted, as is your example data):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have; 
  by Patient_id Treatment_date;
  if first.Patient_id then
    Treatment_no=1;
  else if first.Treatment_date then
    Treatment_no+1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;All pretty simple. The statement "Treatment_no+1" is a "sum" statement, and is equivalent to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Treatment_no=sum(Treatment_no,1);
retain Treatment_no;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 03 Dec 2022 06:11:22 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2022-12-03T06:11:22Z</dc:date>
    <item>
      <title>Registre SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Registre-SAS/m-p/847519#M335076</link>
      <description>Hello,&lt;BR /&gt;I'm trying to auto-create the last column. I tried with a retain but didn't succeed. could you help me please?&lt;BR /&gt;Thanks in advance&lt;BR /&gt;alexandra</description>
      <pubDate>Fri, 02 Dec 2022 23:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Registre-SAS/m-p/847519#M335076</guid>
      <dc:creator>alexandraIFCT</dc:creator>
      <dc:date>2022-12-02T23:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: Registre SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Registre-SAS/m-p/847546#M335084</link>
      <description>&lt;P&gt;Please post your example data as a data step, e.g. like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length Patient_id $1;
  informat Treatment_date mmddyy10.; 
  format Treatment_date mmddyy10.;  
  input Patient_id Treatment_date;
cards;
A 1/1/2020  
A 1/1/2020  
A 5/1/2022  
B 1/12/2021  
C 1/25/2020  
C 6/1t/2021  
D 12/31/2021  
D 12/31/2021  
D 5/25/2022  
D 7/10/2022  
D 7/10/2022  
D 10/4/2022  
;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I guess (you did not describe the result you wanted, just showed the example) the calculation you want can be done like this (data must be sorted, as is your example data):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have; 
  by Patient_id Treatment_date;
  if first.Patient_id then
    Treatment_no=1;
  else if first.Treatment_date then
    Treatment_no+1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;All pretty simple. The statement "Treatment_no+1" is a "sum" statement, and is equivalent to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Treatment_no=sum(Treatment_no,1);
retain Treatment_no;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Dec 2022 06:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Registre-SAS/m-p/847546#M335084</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-12-03T06:11:22Z</dc:date>
    </item>
  </channel>
</rss>

