<?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 Create increasing variable from 1 to 7 and start again when some condtitions are met in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541934#M7436</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that Looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Unbenannt.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/27817i533684BCE45A727F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Unbenannt.png" alt="Unbenannt.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to assign an increasing number from 1 to 7&amp;nbsp;to a new variable when "Time_start_for" change (increase)&amp;nbsp;and:&lt;/P&gt;&lt;P&gt;-ID is the same&lt;/P&gt;&lt;P&gt;-date_for is the same&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when is done should start again with 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To explain me better: every ID (test subject) has on different Dates 7 different "sessions".&lt;/P&gt;&lt;P&gt;The "Time_start_for" is not always the same for all the subjects.&lt;/P&gt;&lt;P&gt;What I want is a new variable that indicate the session number.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Version: 9.4&lt;/P&gt;</description>
    <pubDate>Mon, 11 Mar 2019 10:34:03 GMT</pubDate>
    <dc:creator>riccardo88</dc:creator>
    <dc:date>2019-03-11T10:34:03Z</dc:date>
    <item>
      <title>Create increasing variable from 1 to 7 and start again when some condtitions are met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541934#M7436</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that Looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Unbenannt.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/27817i533684BCE45A727F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Unbenannt.png" alt="Unbenannt.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to assign an increasing number from 1 to 7&amp;nbsp;to a new variable when "Time_start_for" change (increase)&amp;nbsp;and:&lt;/P&gt;&lt;P&gt;-ID is the same&lt;/P&gt;&lt;P&gt;-date_for is the same&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when is done should start again with 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To explain me better: every ID (test subject) has on different Dates 7 different "sessions".&lt;/P&gt;&lt;P&gt;The "Time_start_for" is not always the same for all the subjects.&lt;/P&gt;&lt;P&gt;What I want is a new variable that indicate the session number.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Version: 9.4&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 10:34:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541934#M7436</guid>
      <dc:creator>riccardo88</dc:creator>
      <dc:date>2019-03-11T10:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create increasing variable from 1 to 7 and start again when some condtitions are met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541936#M7437</link>
      <description>&lt;P&gt;Can you provide your data in a usable form?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Makes it much easier to provide a usable code answer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 10:39:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541936#M7437</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-03-11T10:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: Create increasing variable from 1 to 7 and start again when some condtitions are met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541941#M7439</link>
      <description>&lt;PRE&gt;ID,Date_for,Time_start_for,_TYPE_,_FREQ_,_STAT_,HR,Atemfrequenz,SpO2
101,01/31/19,10:19,0,118,N,118,118,118
101,01/31/19,10:19,0,118,MIN,81.5,7.5757575758,95
101,01/31/19,10:19,0,118,MAX,96.25,27.649769585,96
101,01/31/19,10:19,0,118,MEAN,88.846559726,14.766582398,95.156920904
101,01/31/19,10:19,0,118,STD,2.7743979079,2.7931480556,0.305087647
101,01/31/19,11:58,0,140,N,140,140,140
101,01/31/19,11:58,0,140,MIN,75,6.8259385666,89.333333333
101,01/31/19,11:58,0,140,MAX,93,23.346303502,92
101,01/31/19,11:58,0,140,MEAN,83.328511905,17.71234626,90.900436508
101,01/31/19,11:58,0,140,STD,3.1957743662,2.8950150452,0.6360118615
101,01/31/19,13:00,0,151,N,151,151,151
101,01/31/19,13:00,0,151,MIN,78.6,7.5949367089,89
101,01/31/19,13:00,0,151,MAX,92.333333333,23.166023166,92.333333333
101,01/31/19,13:00,0,151,MEAN,85.379801325,18.333250653,90.838410596
101,01/31/19,13:00,0,151,STD,2.5256651737,2.8289307891,0.6783282034
101,01/31/19,14:00,0,154,N,154,154,154
101,01/31/19,14:00,0,154,MIN,67.333333333,6.7643742954,91
101,01/31/19,14:00,0,154,MAX,101.5,30,94
101,01/31/19,14:00,0,154,MEAN,87.054298083,19.278342826,92.448953824
101,01/31/19,14:00,0,154,STD,4.145978296,3.1982577136,0.6179428555
101,01/31/19,15:01,0,150,N,150,150,150
101,01/31/19,15:01,0,150,MIN,78,6.8337129841,91
101,01/31/19,15:01,0,150,MAX,99.2,32.786885246,95
101,01/31/19,15:01,0,150,MEAN,84.734404762,18.504781387,92.669777778
101,01/31/19,15:01,0,150,STD,3.2353262727,3.5150039626,0.7165649131
101,01/31/19,15:58,0,159,N,159,159,159
101,01/31/19,15:58,0,159,MIN,80,9.7879282219,90
101,01/31/19,15:58,0,159,MAX,92,23.529411765,94
101,01/31/19,15:58,0,159,MEAN,86.893186583,19.174924095,91.981551363
101,01/31/19,15:58,0,159,STD,2.496592061,2.3915392137,0.7136098857
101,01/31/19,16:59,0,154,N,154,154,154
101,01/31/19,16:59,0,154,MIN,80.5,6.528835691,92
101,01/31/19,16:59,0,154,MAX,98.333333333,24.291497976,96
101,01/31/19,16:59,0,154,MEAN,88.338899196,19.373919748,93.797186147
101,01/31/19,16:59,0,154,STD,2.6253857217,3.1071420356,0.8541002927
101,02/07/19,9:34,0,138,N,138,138,138
101,02/07/19,9:34,0,138,MIN,83,7.4074074074,96.75
101,02/07/19,9:34,0,138,MAX,96.5,23.255813953,98.666666667
101,02/07/19,9:34,0,138,MEAN,89.338112491,17.429150926,97.667011732
101,02/07/19,9:34,0,138,STD,2.3489566457,3.1713217584,0.4528912065
101,02/07/19,11:00,0,145,N,145,145,145
101,02/07/19,11:00,0,145,MIN,79.666666667,6.0975609756,88
101,02/07/19,11:00,0,145,MAX,90.333333333,23.166023166,92.75
101,02/07/19,11:00,0,145,MEAN,85.648259442,17.757981771,89.848604269
101,02/07/19,11:00,0,145,STD,2.4946143529,2.9558597284,0.8604079029
101,02/07/19,11:57,0,149,N,149,149,149
101,02/07/19,11:57,0,149,MIN,74.666666667,9.2592592593,89
101,02/07/19,11:57,0,149,MAX,86.5,25.210084034,93.666666667
101,02/07/19,11:57,0,149,MEAN,82.228427613,18.242657167,91.121428571
101,02/07/19,11:57,0,149,STD,2.1273408499,3.0168947674,0.9109684751
101,02/07/19,12:58,0,141,N,141,141,141
101,02/07/19,12:58,0,141,MIN,77,5.1063829787,89
101,02/07/19,12:58,0,141,MAX,91,34.88372093,93
101,02/07/19,12:58,0,141,MEAN,84.177090049,18.019936177,91.111583924
101,02/07/19,12:58,0,141,STD,2.9756893198,3.593121113,0.8299501402
101,02/07/19,13:58,0,135,N,135,135,135
101,02/07/19,13:58,0,135,MIN,79,7.3619631902,88.75
101,02/07/19,13:58,0,135,MAX,92,26.200873362,93
101,02/07/19,13:58,0,135,MEAN,85.887460317,16.609089431,89.862345679
101,02/07/19,13:58,0,135,STD,2.3950279785,2.9043491671,0.902890519
101,02/07/19,14:55,0,142,N,142,142,142
101,02/07/19,14:55,0,142,MIN,83.25,8.1190798376,89
101,02/07/19,14:55,0,142,MAX,96.75,21.428571429,93.5
101,02/07/19,14:55,0,142,MEAN,89.697065728,17.453225263,90.860160966
101,02/07/19,14:55,0,142,STD,2.7399597438,2.8494281241,0.6730471505
101,02/07/19,15:59,0,144,N,144,144,144
101,02/07/19,15:59,0,144,MIN,78.5,9.6,89
101,02/07/19,15:59,0,144,MAX,90.666666667,22.556390977,93
101,02/07/19,15:59,0,144,MEAN,85.147106481,17.402927058,90.960532407
101,02/07/19,15:59,0,144,STD,2.5681513657,2.46291814,0.8412646956
126,02/01/19,9:51,0,96,N,96,96,96
126,02/01/19,9:51,0,96,MIN,67.6,7.100591716,95
126,02/01/19,9:51,0,96,MAX,83,22.900763359,97
126,02/01/19,9:51,0,96,MEAN,72.25536541,12.918101228,95.826116071
126,02/01/19,9:51,0,96,STD,2.6607553354,3.5511741217,0.6422341224
126,02/01/19,11:26,0,129,N,129,129,129
126,02/01/19,11:26,0,129,MIN,78,7.2115384615,65.6
126,02/01/19,11:26,0,129,MAX,97,32.432432432,80.666666667
126,02/01/19,11:26,0,129,MEAN,86.562575366,17.138618253,72.190079365
126,02/01/19,11:26,0,129,STD,4.4198323625,5.1557816279,3.2852246717
126,02/01/19,12:25,0,120,N,120,120,120
126,02/01/19,12:25,0,120,MIN,79.5,7.371007371,68
126,02/01/19,12:25,0,120,MAX,99.142857143,27.52293578,77.333333333&lt;/PRE&gt;&lt;P&gt;Like this is ok? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 10:50:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541941#M7439</guid>
      <dc:creator>riccardo88</dc:creator>
      <dc:date>2019-03-11T10:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: Create increasing variable from 1 to 7 and start again when some condtitions are met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541945#M7442</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've made some assumptions, such as the data being sorted in id and date_for order, and come up with the following untested code&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 id date_for;

   session_number + 1;

   if last.date_for then
      session_number = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 11:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541945#M7442</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-03-11T11:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: Create increasing variable from 1 to 7 and start again when some condtitions are met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541949#M7443</link>
      <description>&lt;P&gt;I made a SAS data set from this. So your data looks like below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does each line correspond to a 'session'? If so, I see more than 7 sessions for ID=101 on the date 01/31/19?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Date_for:mmddyy10. Time_start_for $ _TYPE_ _FREQ_ _STAT_ $ HR Atemfrequenz SpO2;
infile datalines dlm=',';
format Date_for mmddyy10.;
datalines;
101,01/31/19,10:19,0,118,N,118,118,118
101,01/31/19,10:19,0,118,MIN,81.5,7.5757575758,95
101,01/31/19,10:19,0,118,MAX,96.25,27.649769585,96
101,01/31/19,10:19,0,118,MEAN,88.846559726,14.766582398,95.156920904
101,01/31/19,10:19,0,118,STD,2.7743979079,2.7931480556,0.305087647
101,01/31/19,11:58,0,140,N,140,140,140
101,01/31/19,11:58,0,140,MIN,75,6.8259385666,89.333333333
101,01/31/19,11:58,0,140,MAX,93,23.346303502,92
101,01/31/19,11:58,0,140,MEAN,83.328511905,17.71234626,90.900436508
101,01/31/19,11:58,0,140,STD,3.1957743662,2.8950150452,0.6360118615
101,01/31/19,13:00,0,151,N,151,151,151
101,01/31/19,13:00,0,151,MIN,78.6,7.5949367089,89
101,01/31/19,13:00,0,151,MAX,92.333333333,23.166023166,92.333333333
101,01/31/19,13:00,0,151,MEAN,85.379801325,18.333250653,90.838410596
101,01/31/19,13:00,0,151,STD,2.5256651737,2.8289307891,0.6783282034
101,01/31/19,14:00,0,154,N,154,154,154
101,01/31/19,14:00,0,154,MIN,67.333333333,6.7643742954,91
101,01/31/19,14:00,0,154,MAX,101.5,30,94
101,01/31/19,14:00,0,154,MEAN,87.054298083,19.278342826,92.448953824
101,01/31/19,14:00,0,154,STD,4.145978296,3.1982577136,0.6179428555
101,01/31/19,15:01,0,150,N,150,150,150
101,01/31/19,15:01,0,150,MIN,78,6.8337129841,91
101,01/31/19,15:01,0,150,MAX,99.2,32.786885246,95
101,01/31/19,15:01,0,150,MEAN,84.734404762,18.504781387,92.669777778
101,01/31/19,15:01,0,150,STD,3.2353262727,3.5150039626,0.7165649131
101,01/31/19,15:58,0,159,N,159,159,159
101,01/31/19,15:58,0,159,MIN,80,9.7879282219,90
101,01/31/19,15:58,0,159,MAX,92,23.529411765,94
101,01/31/19,15:58,0,159,MEAN,86.893186583,19.174924095,91.981551363
101,01/31/19,15:58,0,159,STD,2.496592061,2.3915392137,0.7136098857
101,01/31/19,16:59,0,154,N,154,154,154
101,01/31/19,16:59,0,154,MIN,80.5,6.528835691,92
101,01/31/19,16:59,0,154,MAX,98.333333333,24.291497976,96
101,01/31/19,16:59,0,154,MEAN,88.338899196,19.373919748,93.797186147
101,01/31/19,16:59,0,154,STD,2.6253857217,3.1071420356,0.8541002927
101,02/07/19,9:34,0,138,N,138,138,138
101,02/07/19,9:34,0,138,MIN,83,7.4074074074,96.75
101,02/07/19,9:34,0,138,MAX,96.5,23.255813953,98.666666667
101,02/07/19,9:34,0,138,MEAN,89.338112491,17.429150926,97.667011732
101,02/07/19,9:34,0,138,STD,2.3489566457,3.1713217584,0.4528912065
101,02/07/19,11:00,0,145,N,145,145,145
101,02/07/19,11:00,0,145,MIN,79.666666667,6.0975609756,88
101,02/07/19,11:00,0,145,MAX,90.333333333,23.166023166,92.75
101,02/07/19,11:00,0,145,MEAN,85.648259442,17.757981771,89.848604269
101,02/07/19,11:00,0,145,STD,2.4946143529,2.9558597284,0.8604079029
101,02/07/19,11:57,0,149,N,149,149,149
101,02/07/19,11:57,0,149,MIN,74.666666667,9.2592592593,89
101,02/07/19,11:57,0,149,MAX,86.5,25.210084034,93.666666667
101,02/07/19,11:57,0,149,MEAN,82.228427613,18.242657167,91.121428571
101,02/07/19,11:57,0,149,STD,2.1273408499,3.0168947674,0.9109684751
101,02/07/19,12:58,0,141,N,141,141,141
101,02/07/19,12:58,0,141,MIN,77,5.1063829787,89
101,02/07/19,12:58,0,141,MAX,91,34.88372093,93
101,02/07/19,12:58,0,141,MEAN,84.177090049,18.019936177,91.111583924
101,02/07/19,12:58,0,141,STD,2.9756893198,3.593121113,0.8299501402
101,02/07/19,13:58,0,135,N,135,135,135
101,02/07/19,13:58,0,135,MIN,79,7.3619631902,88.75
101,02/07/19,13:58,0,135,MAX,92,26.200873362,93
101,02/07/19,13:58,0,135,MEAN,85.887460317,16.609089431,89.862345679
101,02/07/19,13:58,0,135,STD,2.3950279785,2.9043491671,0.902890519
101,02/07/19,14:55,0,142,N,142,142,142
101,02/07/19,14:55,0,142,MIN,83.25,8.1190798376,89
101,02/07/19,14:55,0,142,MAX,96.75,21.428571429,93.5
101,02/07/19,14:55,0,142,MEAN,89.697065728,17.453225263,90.860160966
101,02/07/19,14:55,0,142,STD,2.7399597438,2.8494281241,0.6730471505
101,02/07/19,15:59,0,144,N,144,144,144
101,02/07/19,15:59,0,144,MIN,78.5,9.6,89
101,02/07/19,15:59,0,144,MAX,90.666666667,22.556390977,93
101,02/07/19,15:59,0,144,MEAN,85.147106481,17.402927058,90.960532407
101,02/07/19,15:59,0,144,STD,2.5681513657,2.46291814,0.8412646956
126,02/01/19,9:51,0,96,N,96,96,96
126,02/01/19,9:51,0,96,MIN,67.6,7.100591716,95
126,02/01/19,9:51,0,96,MAX,83,22.900763359,97
126,02/01/19,9:51,0,96,MEAN,72.25536541,12.918101228,95.826116071
126,02/01/19,9:51,0,96,STD,2.6607553354,3.5511741217,0.6422341224
126,02/01/19,11:26,0,129,N,129,129,129
126,02/01/19,11:26,0,129,MIN,78,7.2115384615,65.6
126,02/01/19,11:26,0,129,MAX,97,32.432432432,80.666666667
126,02/01/19,11:26,0,129,MEAN,86.562575366,17.138618253,72.190079365
126,02/01/19,11:26,0,129,STD,4.4198323625,5.1557816279,3.2852246717
126,02/01/19,12:25,0,120,N,120,120,120
126,02/01/19,12:25,0,120,MIN,79.5,7.371007371,68
126,02/01/19,12:25,0,120,MAX,99.142857143,27.52293578,77.333333333
;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Mar 2019 11:07:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541949#M7443</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-03-11T11:07:39Z</dc:date>
    </item>
    <item>
      <title>Re: Create increasing variable from 1 to 7 and start again when some condtitions are met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541950#M7444</link>
      <description>&lt;P&gt;Dear Amir,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for answer. Unfortunately is not what I Need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The session_number should be the same for lines with same "Time_start_for", Count up to 7 and then start again from 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Riccardo&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 11:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541950#M7444</guid>
      <dc:creator>riccardo88</dc:creator>
      <dc:date>2019-03-11T11:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create increasing variable from 1 to 7 and start again when some condtitions are met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541951#M7445</link>
      <description>&lt;P&gt;Thank you! No every 5 lines correspond to a session (basically every time "Time_start_for" Changes we have&amp;nbsp;a new session.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And also ID 101 for example has&amp;nbsp;14 sessions but on 2&amp;nbsp;different days. On both days the sessions should be marked from 1 to 7.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 11:13:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541951#M7445</guid>
      <dc:creator>riccardo88</dc:creator>
      <dc:date>2019-03-11T11:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: Create increasing variable from 1 to 7 and start again when some condtitions are met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541961#M7446</link>
      <description>&lt;P&gt;How about the following:&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 id date_for;

   if first.date_for then
      session_number + 1;

   if last.id then
      session_number = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Mar 2019 11:28:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541961#M7446</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-03-11T11:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: Create increasing variable from 1 to 7 and start again when some condtitions are met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541962#M7447</link>
      <description>Doesn't work. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;It gives me session_number is equal1 for every observation.</description>
      <pubDate>Mon, 11 Mar 2019 11:32:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541962#M7447</guid>
      <dc:creator>riccardo88</dc:creator>
      <dc:date>2019-03-11T11:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: Create increasing variable from 1 to 7 and start again when some condtitions are met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541965#M7449</link>
      <description>&lt;P&gt;Show us the expected numbers for every observation of&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm=',';
input ID Date_for:mmddyy10.;
format Date_for mmddyy10.;
datalines;
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
101,01/31/19
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Mar 2019 11:38:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541965#M7449</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-11T11:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create increasing variable from 1 to 7 and start again when some condtitions are met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541967#M7450</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input ID Date_for:mmddyy10. Time_start_for $ Session;
infile datalines dlm=',';
format Date_for mmddyy10.;
datalines;
101,01/31/19,10:19,1
101,01/31/19,10:19,1
101,01/31/19,10:19,1
101,01/31/19,10:19,1
101,01/31/19,10:19,1
101,01/31/19,11:58,2
101,01/31/19,11:58,2
101,01/31/19,11:58,2
101,01/31/19,11:58,2
101,01/31/19,11:58,2
101,01/31/19,13:00,3
101,01/31/19,13:00,3
101,01/31/19,13:00,3
101,01/31/19,13:00,3
101,01/31/19,13:00,3
101,01/31/19,14:00,4
101,01/31/19,14:00,4
101,01/31/19,14:00,4
101,01/31/19,14:00,4
101,01/31/19,14:00,4
101,01/31/19,15:01,5
101,01/31/19,15:01,5
101,01/31/19,15:01,5
101,01/31/19,15:01,5
101,01/31/19,15:01,5
101,01/31/19,15:58,6
101,01/31/19,15:58,6
101,01/31/19,15:58,6
101,01/31/19,15:58,6
101,01/31/19,15:58,6
101,01/31/19,16:59,7
101,01/31/19,16:59,7
101,01/31/19,16:59,7
101,01/31/19,16:59,7
101,01/31/19,16:59,7
101,02/07/19,9:34,1
101,02/07/19,9:34,1
101,02/07/19,9:34,1
101,02/07/19,9:34,1
101,02/07/19,9:34,1
101,02/07/19,11:00,2
101,02/07/19,11:00,2
101,02/07/19,11:00,2
101,02/07/19,11:00,2
101,02/07/19,11:00,2
101,02/07/19,11:57,3
101,02/07/19,11:57,3
101,02/07/19,11:57,3
101,02/07/19,11:57,3
101,02/07/19,11:57,3
101,02/07/19,12:58,4
101,02/07/19,12:58,4
101,02/07/19,12:58,4
101,02/07/19,12:58,4
101,02/07/19,12:58,4
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The session has to Change when "Time_start_for" changes so this variable is also required.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 11:47:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541967#M7450</guid>
      <dc:creator>riccardo88</dc:creator>
      <dc:date>2019-03-11T11:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create increasing variable from 1 to 7 and start again when some condtitions are met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541976#M7452</link>
      <description>&lt;P&gt;So this does it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Date_for:mmddyy10. Time_start_for :time5.;
infile datalines dlm=',';
format Date_for mmddyy10. Time_start_for time5.;
datalines;
101,01/31/19,10:19
101,01/31/19,10:19
101,01/31/19,10:19
101,01/31/19,10:19
101,01/31/19,10:19
101,01/31/19,11:58
101,01/31/19,11:58
101,01/31/19,11:58
101,01/31/19,11:58
101,01/31/19,11:58
101,01/31/19,13:00
101,01/31/19,13:00
101,01/31/19,13:00
101,01/31/19,13:00
101,01/31/19,13:00
101,01/31/19,14:00
101,01/31/19,14:00
101,01/31/19,14:00
101,01/31/19,14:00
101,01/31/19,14:00
101,01/31/19,15:01
101,01/31/19,15:01
101,01/31/19,15:01
101,01/31/19,15:01
101,01/31/19,15:01
101,01/31/19,15:58
101,01/31/19,15:58
101,01/31/19,15:58
101,01/31/19,15:58
101,01/31/19,15:58
101,01/31/19,16:59
101,01/31/19,16:59
101,01/31/19,16:59
101,01/31/19,16:59
101,01/31/19,16:59
101,02/07/19,9:34
101,02/07/19,9:34
101,02/07/19,9:34
101,02/07/19,9:34
101,02/07/19,9:34
101,02/07/19,11:00
101,02/07/19,11:00
101,02/07/19,11:00
101,02/07/19,11:00
101,02/07/19,11:00
101,02/07/19,11:57
101,02/07/19,11:57
101,02/07/19,11:57
101,02/07/19,11:57
101,02/07/19,11:57
101,02/07/19,12:58
101,02/07/19,12:58
101,02/07/19,12:58
101,02/07/19,12:58
101,02/07/19,12:58
;
run;

data want;
set have;
by id date_for time_start_for;
if first.date_for then session = 0;
if first.time_start_for then session + 1;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;                      Time_
                      start_
  ID      Date_for     for      session

 101    01/31/2019    10:19        1   
 101    01/31/2019    10:19        1   
 101    01/31/2019    10:19        1   
 101    01/31/2019    10:19        1   
 101    01/31/2019    10:19        1   
 101    01/31/2019    11:58        2   
 101    01/31/2019    11:58        2   
 101    01/31/2019    11:58        2   
 101    01/31/2019    11:58        2   
 101    01/31/2019    11:58        2   
 101    01/31/2019    13:00        3   
 101    01/31/2019    13:00        3   
 101    01/31/2019    13:00        3   
 101    01/31/2019    13:00        3   
 101    01/31/2019    13:00        3   
 101    01/31/2019    14:00        4   
 101    01/31/2019    14:00        4   
 101    01/31/2019    14:00        4   
 101    01/31/2019    14:00        4   
 101    01/31/2019    14:00        4   
 101    01/31/2019    15:01        5   
 101    01/31/2019    15:01        5   
 101    01/31/2019    15:01        5   
 101    01/31/2019    15:01        5   
 101    01/31/2019    15:01        5   
 101    01/31/2019    15:58        6   
 101    01/31/2019    15:58        6   
 101    01/31/2019    15:58        6   
 101    01/31/2019    15:58        6   
 101    01/31/2019    15:58        6   
 101    01/31/2019    16:59        7   
 101    01/31/2019    16:59        7   
 101    01/31/2019    16:59        7   
 101    01/31/2019    16:59        7   
 101    01/31/2019    16:59        7   
 101    02/07/2019     9:34        1   
 101    02/07/2019     9:34        1   
 101    02/07/2019     9:34        1   
 101    02/07/2019     9:34        1   
 101    02/07/2019     9:34        1   
 101    02/07/2019    11:00        2   
 101    02/07/2019    11:00        2   
 101    02/07/2019    11:00        2   
 101    02/07/2019    11:00        2   
 101    02/07/2019    11:00        2   
 101    02/07/2019    11:57        3   
 101    02/07/2019    11:57        3   
 101    02/07/2019    11:57        3   
 101    02/07/2019    11:57        3   
 101    02/07/2019    11:57        3   
 101    02/07/2019    12:58        4   
 101    02/07/2019    12:58        4   
 101    02/07/2019    12:58        4   
 101    02/07/2019    12:58        4   
 101    02/07/2019    12:58        4   
&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Mar 2019 12:19:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541976#M7452</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-11T12:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: Create increasing variable from 1 to 7 and start again when some condtitions are met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541978#M7454</link>
      <description>&lt;P&gt;How about the following. I set up &lt;FONT face="courier new,courier"&gt;Time_start_for&lt;/FONT&gt; to be numeric rather than character and created &lt;FONT face="courier new,courier"&gt;check&lt;/FONT&gt; to see if &lt;FONT face="courier new,courier"&gt;session_number&lt;/FONT&gt; equals &lt;FONT face="courier new,courier"&gt;Session&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input ID Date_for:mmddyy10. Time_start_for:time5. Session;
   infile datalines dlm=',';
   format Date_for       mmddyy10.
          Time_start_for time5.
   ;
   datalines;
101,01/31/19,10:19,1
101,01/31/19,10:19,1
101,01/31/19,10:19,1
101,01/31/19,10:19,1
101,01/31/19,10:19,1
101,01/31/19,11:58,2
101,01/31/19,11:58,2
101,01/31/19,11:58,2
101,01/31/19,11:58,2
101,01/31/19,11:58,2
101,01/31/19,13:00,3
101,01/31/19,13:00,3
101,01/31/19,13:00,3
101,01/31/19,13:00,3
101,01/31/19,13:00,3
101,01/31/19,14:00,4
101,01/31/19,14:00,4
101,01/31/19,14:00,4
101,01/31/19,14:00,4
101,01/31/19,14:00,4
101,01/31/19,15:01,5
101,01/31/19,15:01,5
101,01/31/19,15:01,5
101,01/31/19,15:01,5
101,01/31/19,15:01,5
101,01/31/19,15:58,6
101,01/31/19,15:58,6
101,01/31/19,15:58,6
101,01/31/19,15:58,6
101,01/31/19,15:58,6
101,01/31/19,16:59,7
101,01/31/19,16:59,7
101,01/31/19,16:59,7
101,01/31/19,16:59,7
101,01/31/19,16:59,7
101,02/07/19,9:34,1
101,02/07/19,9:34,1
101,02/07/19,9:34,1
101,02/07/19,9:34,1
101,02/07/19,9:34,1
101,02/07/19,11:00,2
101,02/07/19,11:00,2
101,02/07/19,11:00,2
101,02/07/19,11:00,2
101,02/07/19,11:00,2
101,02/07/19,11:57,3
101,02/07/19,11:57,3
101,02/07/19,11:57,3
101,02/07/19,11:57,3
101,02/07/19,11:57,3
101,02/07/19,12:58,4
101,02/07/19,12:58,4
101,02/07/19,12:58,4
101,02/07/19,12:58,4
101,02/07/19,12:58,4
;
run;

data want;
   set have;
   by id date_for time_start_for;

   if first.time_start_for then
      session_number + 1;

   check = (session = session_number);

   if last.date_for then
      session_number = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Mar 2019 12:21:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541978#M7454</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-03-11T12:21:13Z</dc:date>
    </item>
    <item>
      <title>Re: Create increasing variable from 1 to 7 and start again when some condtitions are met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541979#M7455</link>
      <description>&lt;P&gt;Your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   by id date_for time_start_for;

   if first.time_start_for then
      session_number + 1;

   check = (session = session_number);

   if last.date_for then
      session_number = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;creates a wrong result (session = 0) for every last observation of a date_for group.&lt;/P&gt;
&lt;P&gt;Reset counters at the beginning of a group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: Belay that. I mistook session_number for session. Still this code looks unnecessarily complicated to me.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 12:34:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541979#M7455</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-11T12:34:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create increasing variable from 1 to 7 and start again when some condtitions are met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541984#M7458</link>
      <description>Thanks a lot!</description>
      <pubDate>Mon, 11 Mar 2019 12:41:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541984#M7458</guid>
      <dc:creator>riccardo88</dc:creator>
      <dc:date>2019-03-11T12:41:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create increasing variable from 1 to 7 and start again when some condtitions are met</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541986#M7459</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; agreed. Rushing to do too many (other) things at the same time.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 12:44:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-increasing-variable-from-1-to-7-and-start-again-when-some/m-p/541986#M7459</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-03-11T12:44:33Z</dc:date>
    </item>
  </channel>
</rss>

