<?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: Assign value based on first dose in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341170#M78052</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;: &amp;nbsp;Actually, i &amp;nbsp;do not want to remove the value column before the assignment of values. In the actual dataset, there are already several dosing events and the correponsing "value" per subject. ALso, in some &amp;nbsp;case &amp;nbsp;rows before the first dosing event has corresponsing "value", which should not be changed. &amp;nbsp;I have edited the input datasaet to &amp;nbsp;make it clear. Thanks&lt;/P&gt;</description>
    <pubDate>Wed, 15 Mar 2017 13:00:05 GMT</pubDate>
    <dc:creator>ari</dc:creator>
    <dc:date>2017-03-15T13:00:05Z</dc:date>
    <item>
      <title>Assign value based on first dose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341157#M78044</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;infile id date time dose i value;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 8/24/2010 13:07 0 2 1&lt;BR /&gt;1 8/24/2010 9:53 0 2 2&lt;BR /&gt;1 8/24/2010 13:07 0 2 3&lt;BR /&gt;1 8/24/2010 9:53 0 2 4&lt;BR /&gt;1 8/24/2010 10:30 1 2 0&lt;BR /&gt;1 8/31/2010 9:20 0 2 0&lt;BR /&gt;1 8/31/2010 9:20 0 2 0&lt;BR /&gt;1 8/31/2010 9:40 1 2 0&lt;BR /&gt;;;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;input id date $ time $ dose i value;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 8/24/2010 13:07 0 2 1&lt;BR /&gt;1 8/24/2010 9:53 0 2 2&lt;BR /&gt;1 8/24/2010 13:07 0 2 3&lt;BR /&gt;1 8/24/2010 9:53 0 2 4&lt;BR /&gt;1 8/24/2010 10:30 1 2 2&lt;BR /&gt;1 8/31/2010 9:20 0 2 2&lt;BR /&gt;1 8/31/2010 9:20 0 2 2&lt;BR /&gt;1 8/31/2010 9:40 1 2 0&lt;BR /&gt;;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the column dose indicates the dosing events (dose=1). &amp;nbsp;I want to assign value=i, if the first dosing event is 1 and value=0 and carry that until the next dose.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 13:19:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341157#M78044</guid>
      <dc:creator>ari</dc:creator>
      <dc:date>2017-03-15T13:19:18Z</dc:date>
    </item>
    <item>
      <title>Re: Assign value based on first dose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341167#M78051</link>
      <description>&lt;P&gt;Do make sure your test data code actually works before posting, there are errors throughout that code. &amp;nbsp;Note in the below I haven't fixed it anymore than necessary to get it working - i.e. dates/times are not right but doesn't affect logic.&lt;/P&gt;
&lt;PRE&gt;data have (drop=value);
  input id date $ time $ dose i value;
datalines;
1 8/24/2010 13:07 0 2 0
1 8/24/2010 9:53 0 2 0
1 8/24/2010 13:07 0 2 0
1 8/24/2010 9:53 0 2 0
1 8/24/2010 10:30 1 2 0
1 8/31/2010 9:20 0 2 0
1 8/31/2010 9:20 0 2 0
1 8/31/2010 9:40 1 2 0
;
run;
data want;
  set have;
  retain value;
  by id;
  if first.id then value=0;
  if dose=1 and value=0 then value=i;
  else if dose=1 and value ne 0 then value=0;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Mar 2017 12:46:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341167#M78051</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-15T12:46:09Z</dc:date>
    </item>
    <item>
      <title>Re: Assign value based on first dose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341170#M78052</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;: &amp;nbsp;Actually, i &amp;nbsp;do not want to remove the value column before the assignment of values. In the actual dataset, there are already several dosing events and the correponsing "value" per subject. ALso, in some &amp;nbsp;case &amp;nbsp;rows before the first dosing event has corresponsing "value", which should not be changed. &amp;nbsp;I have edited the input datasaet to &amp;nbsp;make it clear. Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 13:00:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341170#M78052</guid>
      <dc:creator>ari</dc:creator>
      <dc:date>2017-03-15T13:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: Assign value based on first dose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341183#M78058</link>
      <description>&lt;P&gt;Well, you need ot have a variable to retain, so just keep a second one:&lt;/P&gt;
&lt;PRE&gt;data have;
  input id date $ time $ dose i value;
datalines;
1 8/24/2010 13:07 0 2 0
1 8/24/2010 9:53 0 2 0
1 8/24/2010 13:07 0 2 0
1 8/24/2010 9:53 0 2 0
1 8/24/2010 10:30 1 2 0
1 8/31/2010 9:20 0 2 0
1 8/31/2010 9:20 0 2 0
1 8/31/2010 9:40 1 2 0
;
run;
data want (drop=v);
  set have;
  retain value;
  by id;
  if first.id then v=0;
  if dose=1 and v=0 then v=i;
  else if dose=1 and v ne 0 then v=0;&lt;BR /&gt;  if v ne 0 then value=v;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 13:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341183#M78058</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-15T13:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: Assign value based on first dose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341219#M78070</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/82839"&gt;@ari&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;infile id date time dose i value;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;1 8/24/2010 13:07 0 2 1&lt;BR /&gt;1 8/24/2010 9:53 0 2 2&lt;BR /&gt;1 8/24/2010 13:07 0 2 3&lt;BR /&gt;1 8/24/2010 9:53 0 2 4&lt;BR /&gt;1 8/24/2010 10:30 1 2 0&lt;BR /&gt;1 8/31/2010 9:20 0 2 0&lt;BR /&gt;1 8/31/2010 9:20 0 2 0&lt;BR /&gt;1 8/31/2010 9:40 1 2 0&lt;BR /&gt;;;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;input id date $ time $ dose i value;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;1 8/24/2010 13:07 0 2 1&lt;BR /&gt;1 8/24/2010 9:53 0 2 2&lt;BR /&gt;1 8/24/2010 13:07 0 2 3&lt;BR /&gt;1 8/24/2010 9:53 0 2 4&lt;BR /&gt;1 8/24/2010 10:30 1 2 2&lt;BR /&gt;1 8/31/2010 9:20 0 2 2&lt;BR /&gt;1 8/31/2010 9:20 0 2 2&lt;BR /&gt;1 8/31/2010 9:40 1 2 0&lt;BR /&gt;;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't see any difference between your have and want data sets&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 14:55:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341219#M78070</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-15T14:55:59Z</dc:date>
    </item>
    <item>
      <title>Re: Assign value based on first dose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341223#M78072</link>
      <description>&lt;P&gt;value=2 instead of 0 on rows 5 to 7.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 15:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341223#M78072</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-03-15T15:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: Assign value based on first dose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341414#M78135</link>
      <description>&lt;PRE&gt;
data have;
input id date : $20. time $ dose i value;
datalines;
1 8/24/2010 13:07 0 2 1
1 8/24/2010 9:53 0 2 2
1 8/24/2010 13:07 0 2 3
1 8/24/2010 9:53 0 2 4
1 8/24/2010 10:30 1 2 0
1 8/31/2010 9:20 0 2 0
1 8/31/2010 9:20 0 2 0
1 8/31/2010 9:40 1 2 0
;
run;
data want;
 set have;
 by id;
 retain flag v;
 if first.id then do;flag=0;v=.;end;
 if dose=1 then flag=not flag;
 if dose=1 and flag then v=i;
 if flag then value=v;
 drop i v flag;
run;

&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Mar 2017 04:36:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341414#M78135</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-03-16T04:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: Assign value based on first dose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341442#M78148</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;: This works but I want only &amp;nbsp;the first occurance of dose=1 and the subsequent rows until the next dose be changed.&lt;/P&gt;&lt;P&gt;As of now the code changes all the doses and the subsequent rows. Any help? Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 07:27:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341442#M78148</guid>
      <dc:creator>ari</dc:creator>
      <dc:date>2017-03-16T07:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: Assign value based on first dose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341519#M78193</link>
      <description>&lt;PRE&gt;
You only want change one time. That would be more simple.


data have;
input id date : $20. time $ dose i value;
datalines;
1 8/24/2010 13:07 0 2 1
1 8/24/2010 9:53 0 2 2
1 8/24/2010 13:07 0 2 3
1 8/24/2010 9:53 0 2 4
1 8/24/2010 10:30 1 2 0
1 8/31/2010 9:20 0 2 0
1 8/31/2010 9:20 0 2 0
1 8/31/2010 9:40 1 2 0
;
run;
data want;
 set have;
 by id;
 retain v;
 if first.id then do;n=0;v=.;end;
 if dose=1 then n+1;
 if dose=1 and n=1 then v=i;
 if n=1 then value=v;
 drop i v n;
run;


&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Mar 2017 10:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341519#M78193</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-03-16T10:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: Assign value based on first dose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341520#M78194</link>
      <description>&lt;PRE&gt;
OR you want this ?


data have;
input id date : $20. time $ dose i value;
datalines;
1 8/24/2010 13:07 0 2 1
1 8/24/2010 9:53 0 2 2
1 8/24/2010 13:07 0 2 3
1 8/24/2010 9:53 0 2 4
1 8/24/2010 10:30 1 2 0
1 8/31/2010 9:20 0 2 0
1 8/31/2010 9:20 0 2 0
1 8/31/2010 9:40 1 2 0
;
run;
data want;
 set have;
 by id;
 if first.id then n=0;
 if dose=1 then n+1;
 if n=1 then value=i;
 drop   n;
run;


&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Mar 2017 10:29:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341520#M78194</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-03-16T10:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: Assign value based on first dose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341715#M78247</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;: Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 18:31:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-value-based-on-first-dose/m-p/341715#M78247</guid>
      <dc:creator>ari</dc:creator>
      <dc:date>2017-03-16T18:31:30Z</dc:date>
    </item>
  </channel>
</rss>

