<?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: How to add rows based on variable values in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-add-rows-based-on-variable-values/m-p/558866#M17092</link>
    <description>&lt;P&gt;&lt;STRONG&gt;This is dataset i want one 'add State name where Texas&amp;nbsp; ' and i also give needed output below .&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I just&amp;nbsp; refer&amp;nbsp;&lt;A href="http://technico.qnownow.com/sas-project-4-govt-sas-technical-problem-solve-diy/" target="_self"&gt;sample project&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;i will try&amp;nbsp; &amp;nbsp; just use transpose duplicate values occur how to show below output help me.&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;data work1;
input STATE_NAME $	Total_Number	CATEGORY_DESCRIPTION $;
cards;
Georgia	45	&amp;lt; 10 years
Texas	100	&amp;lt; 10 years
Texas	10	&amp;lt; 10 years
Georgia	67	&amp;gt; 40 years
Texas	60	&amp;gt; 40 years
Texas	50	&amp;gt; 40 years
Georgia	100	Between 10 and 20 years
Texas	20	Between 10 and 20 years
Texas	10	Between 10 and 20 years
Georgia	56	Between 20 and 40 years
Texas	40	Between 20 and 40 years
Texas	40	Between 20 and 40 years
;
run;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;just want like this output help me.&lt;BR /&gt;&lt;/STRONG&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 430px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29536i2A021AC4FAF0D75E/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 15 May 2019 11:20:17 GMT</pubDate>
    <dc:creator>xtremexkumar</dc:creator>
    <dc:date>2019-05-15T11:20:17Z</dc:date>
    <item>
      <title>How to add rows based on variable values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-add-rows-based-on-variable-values/m-p/537241#M16569</link>
      <description>&lt;P&gt;I am working on antibiotic data and need to consider the extended effect of the medication. For this I need to add data for three more days since the last date of medication.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actual Data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Antibiotic1&amp;nbsp;&amp;nbsp;Antibiotic2&amp;nbsp;Antibiotic3&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 10/1/18&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 10/2/18&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 10/3/18&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data I want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Antibiotic1&amp;nbsp;&amp;nbsp;Antibiotic2&amp;nbsp;Antibiotic3&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 10/1/18&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 10/2/18&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt; 1&amp;nbsp;&lt;/STRONG&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 10/3/18&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt; 1&amp;nbsp;&lt;/STRONG&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1&amp;nbsp; 10/4/18&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1&amp;nbsp; 10/5/18&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1&amp;nbsp; 10/6/18&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I code this either in data step or using proc sql?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Feb 2019 22:36:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-add-rows-based-on-variable-values/m-p/537241#M16569</guid>
      <dc:creator>kp19</dc:creator>
      <dc:date>2019-02-20T22:36:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to add rows based on variable values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-add-rows-based-on-variable-values/m-p/537246#M16571</link>
      <description>&lt;P&gt;if "&lt;SPAN&gt;&amp;nbsp;I need to add data for three more days since the last date of medication." is the requirement&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;the last date of medication for id 1 is 3rd oct, and why is&amp;nbsp;Antibiotic2 1 till the 4th in want&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;EDIT: I think I am getting it.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Feb 2019 22:48:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-add-rows-based-on-variable-values/m-p/537246#M16571</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-20T22:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to add rows based on variable values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-add-rows-based-on-variable-values/m-p/537248#M16572</link>
      <description>&lt;P&gt;The data needs to be added for three more days for each antibiotic. Since the antibiotic2 was last given on 1/10/18 the next three days for anibiotic2 become 1.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Feb 2019 22:50:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-add-rows-based-on-variable-values/m-p/537248#M16572</guid>
      <dc:creator>kp19</dc:creator>
      <dc:date>2019-02-20T22:50:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to add rows based on variable values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-add-rows-based-on-variable-values/m-p/537252#M16573</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 
data have;
input ID    Date   :mmddyy8.     Antibiotic1  Antibiotic2 Antibiotic3;
format date mmddyy8.;
cards;
1  10/1/18           0                    1             0
1  10/2/18           1                    0             0
1  10/3/18           1                    0             0
;
proc transpose data=have out=_have;
by id date ;
var Antibiotic:;
run;
proc sort data=_have out=__have;
by id _name_;
run;

data w;
set __have;
by id _name_ col1 notsorted;
output;
if last.col1 and col1 then 
do date=date+1 to date+3;
output;
end;
run;
proc sort data=w out=w1;
by id date;
run;
data w2;
set w1;
by id date _name_;
if first._name_;
run;

proc transpose data=w2 out=want;
by id date ;
var col1;
id _name_;
run;

data final_want;
set want;
array t(*)  Antibiotic:;
do _n_=1 to dim(t);
if missing(t(_n_)) then t(_n_)=0;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Feb 2019 23:19:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-add-rows-based-on-variable-values/m-p/537252#M16573</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-20T23:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to add rows based on variable values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-add-rows-based-on-variable-values/m-p/537296#M16574</link>
      <description>&lt;P&gt;My take on this, a single step solution:&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 :mmddyy. Antibiotic1 Antibiotic2 Antibiotic3;
format date yymmdd10.;
datalines;
1  10/1/18           0                    1             0
1  10/2/18           1                    0             0
1  10/3/18           1                    0             0
;

data want;
array a antibiotic1-antibiotic3;
array e effect1-effect3;
array d_{3};
do until (last.id);
    set have; by id;
    do i = 1 to dim(a);
        if a{i} then do;
            d_{i} = date;
            e{i} = 1;
            end;
        else if intnx("day", date, -3) &amp;gt; d_{i} then e{i} = 0;
        end;
    output;
    end;

do j = 1 to 3;
    date = intnx("day", date, 1);
    do i = 1 to dim(a);
        if intnx("day", date, -3) &amp;gt; d_{i} then e{i} = 0;
        end;
    if max(of e{*}) then output; 
    else leave;
    end;
drop d_: i j;
run;
            
proc print data=want noobs; var id date effect:; run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Feb 2019 04:11:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-add-rows-based-on-variable-values/m-p/537296#M16574</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-02-21T04:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to add rows based on variable values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-add-rows-based-on-variable-values/m-p/537455#M16579</link>
      <description>&lt;P&gt;Thanks a lot for this one step solution! It worked out great.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2019 16:47:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-add-rows-based-on-variable-values/m-p/537455#M16579</guid>
      <dc:creator>kp19</dc:creator>
      <dc:date>2019-02-21T16:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to add rows based on variable values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-add-rows-based-on-variable-values/m-p/558866#M17092</link>
      <description>&lt;P&gt;&lt;STRONG&gt;This is dataset i want one 'add State name where Texas&amp;nbsp; ' and i also give needed output below .&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I just&amp;nbsp; refer&amp;nbsp;&lt;A href="http://technico.qnownow.com/sas-project-4-govt-sas-technical-problem-solve-diy/" target="_self"&gt;sample project&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;i will try&amp;nbsp; &amp;nbsp; just use transpose duplicate values occur how to show below output help me.&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;data work1;
input STATE_NAME $	Total_Number	CATEGORY_DESCRIPTION $;
cards;
Georgia	45	&amp;lt; 10 years
Texas	100	&amp;lt; 10 years
Texas	10	&amp;lt; 10 years
Georgia	67	&amp;gt; 40 years
Texas	60	&amp;gt; 40 years
Texas	50	&amp;gt; 40 years
Georgia	100	Between 10 and 20 years
Texas	20	Between 10 and 20 years
Texas	10	Between 10 and 20 years
Georgia	56	Between 20 and 40 years
Texas	40	Between 20 and 40 years
Texas	40	Between 20 and 40 years
;
run;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;just want like this output help me.&lt;BR /&gt;&lt;/STRONG&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 430px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29536i2A021AC4FAF0D75E/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 11:20:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-add-rows-based-on-variable-values/m-p/558866#M17092</guid>
      <dc:creator>xtremexkumar</dc:creator>
      <dc:date>2019-05-15T11:20:17Z</dc:date>
    </item>
  </channel>
</rss>

