<?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: If statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-statement/m-p/231530#M268078</link>
    <description>&lt;P&gt;yes, please find the atatched excel sheet&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 25 Oct 2015 07:36:15 GMT</pubDate>
    <dc:creator>SalmaTas</dc:creator>
    <dc:date>2015-10-25T07:36:15Z</dc:date>
    <item>
      <title>If statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-statement/m-p/231526#M268076</link>
      <description>&lt;P&gt;there is a nested IF Statement i apply in excel, and i want to know how I do it in SAS Programming, i am sure it is doable, i am just not sure how to do it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;ex:&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have a table containing the below data&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Color&amp;nbsp;&lt;/P&gt;&lt;P&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Blue&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Yellow&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Green&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Pink&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;345&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Red&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;345&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;Blue&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;345&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;White&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;the result i want is:&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Color&amp;nbsp;&lt;/P&gt;&lt;P&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Blue,&amp;nbsp;&lt;SPAN&gt;Yellow,&amp;nbsp;Green&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Blue,&amp;nbsp;&lt;SPAN&gt;Yellow,&amp;nbsp;Green&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Blue,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Yellow,&amp;nbsp;Green&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;345&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Pink,&amp;nbsp;Red,&amp;nbsp;Blue,&amp;nbsp;White&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;345&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Pink,&amp;nbsp;Red,&amp;nbsp;Blue,&amp;nbsp;White&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;345&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Pink,&amp;nbsp;Red,&amp;nbsp;Blue,&amp;nbsp;White&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;345&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Pink,&amp;nbsp;Red,&amp;nbsp;Blue,&amp;nbsp;White&lt;/SPAN&gt;&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;the IF Statements i use for the first option (where there is 3 duplicated ID number, for the 9th row) is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;=IF((A9=A8)*AND(A9=A7),G7&amp;amp;"," G8&amp;amp;","&amp;amp;G9,(IF((A9=A8)*AND(A9=A10),G8&amp;amp;"," &amp;amp;G9&amp;amp;","G10,(IF((A9=A10)*AND(A9=A11),G9&amp;amp;G10&amp;amp;G11))))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;the IF Statements i use for the second&amp;nbsp;option (where there is 4&amp;nbsp;duplicated ID number, for the 16th row) is:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;=IF((A16=A15)*AND(A16=A14)*AND(A13=A16),G13&amp;amp;","&amp;amp;G14&amp;amp;","&amp;amp;G15&amp;amp;","&amp;amp;G16,(IF((A16=A14)*AND(A16=A15)*AND(A16=A17),G14&amp;amp;","&amp;amp;G15&amp;amp;","&amp;amp;G16&amp;amp;","&amp;amp;G17,(IF((A16=A15)*AND(A16=A17)*AND(A16=A18),G15&amp;amp;","&amp;amp;G16&amp;amp;","&amp;amp;G17&amp;amp;","&amp;amp;G18,(IF((A16=A17)*AND(A16=A18)*AND(A16=A19),G16&amp;amp;","&amp;amp;G17&amp;amp;","&amp;amp;G18&amp;amp;","&amp;amp;G19)))))))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;how do i get the same result using SAS Programming?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Oct 2015 06:21:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-statement/m-p/231526#M268076</guid>
      <dc:creator>SalmaTas</dc:creator>
      <dc:date>2015-10-25T06:21:08Z</dc:date>
    </item>
    <item>
      <title>Re: If statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-statement/m-p/231528#M268077</link>
      <description>&lt;P&gt;The actual Excel sheet may help. Is it possible to attach here ?&lt;/P&gt;</description>
      <pubDate>Sun, 25 Oct 2015 06:33:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-statement/m-p/231528#M268077</guid>
      <dc:creator>kannand</dc:creator>
      <dc:date>2015-10-25T06:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: If statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-statement/m-p/231530#M268078</link>
      <description>&lt;P&gt;yes, please find the atatched excel sheet&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Oct 2015 07:36:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-statement/m-p/231530#M268078</guid>
      <dc:creator>SalmaTas</dc:creator>
      <dc:date>2015-10-25T07:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: If statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-statement/m-p/231533#M268079</link>
      <description>&lt;P&gt;One way to go:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 infile datalines truncover;
 input ID Color $;
datalines; 
123 Blue
123 Yellow
123 Green
345 Pink
345 Red
345 Blue
345 White
;
run;

proc transpose data=have out=inter prefix=_color;
  by id;
  var color;
run;

data want(drop=_:);
  merge have(keep=id) inter;
  by id;
  length color $255;
  color=catx(',',of _color:);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or this way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want(drop=_:);
  set have(keep=id);
  by id;
  length color $255;
  retain color;
  if first.id then
    do;
      call missing(color);
      do until(last._id2);
        set have(rename=(id=_id2 color=_color2));
        by _id2;
        color=catx(',',color,_color2);
      end;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or this way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data inter(drop=_:);
  set have(rename=(color=_color));
  by id;
  length color $255;
  retain color;
  color=catx(',',color,_color);
  if last.id then
    do;
      output;
      call missing(color);
    end;
run;

proc sql;
  create table want as
    select r.id, r.color
    from have l, inter r
    where l.id=r.id
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Oct 2015 08:51:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-statement/m-p/231533#M268079</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-10-25T08:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: If statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-statement/m-p/231538#M268080</link>
      <description>thanks a lot for the great support.</description>
      <pubDate>Sun, 25 Oct 2015 09:36:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-statement/m-p/231538#M268080</guid>
      <dc:creator>SalmaTas</dc:creator>
      <dc:date>2015-10-25T09:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: If statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-statement/m-p/231541#M268081</link>
      <description>&lt;P&gt;Still another method:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=oldcolor count index);
set have (rename=(color=oldcolor));
by id;
length color $ 200;
if first.id
then do;
  count = 0;
  color = '';
end;
color = catx(',',trim(color),oldcolor);
count + 1;
if last.id
then do;
  do index = 1 to count;
    output;
  end;
end;
run;
  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Oct 2015 12:04:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-statement/m-p/231541#M268081</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-10-25T12:04:30Z</dc:date>
    </item>
  </channel>
</rss>

