<?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 if all the values in the same by a group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-all-the-values-in-the-same-by-a-group/m-p/615725#M180129</link>
    <description>&lt;P&gt;Hi all!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ' d like to know , all the values in a group (group=id1 and id2) is the same or not.&lt;/P&gt;&lt;P&gt;if id=1 and id2=a then FREQ = MONTH and DAY then 'ERR'. if all the same in the group then FREQ='ERR'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sample:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id1 $1. id2 $1. FREQ $5. ;
cards;
0 w YEAR
1 a	MONTH
1 a MONTH
1 a DAY
1 a DAY
1 a DAY
1 b MONTH
2 c WEEK
2 c WEEK
2 c WEEK
3 d WEEK
3 d DAY
3 a WEEK
;
run;

data want;
input id1 $1. id2 $1. FREQ $5. FLAG $5.;
cards;
0 w YEAR 	YEAR
1 a	MONTH	ERR
1 a MONTH	ERR
1 a DAY		ERR
1 a DAY 	ERR
1 a DAY 	ERR
1 b MONTH	MONTH
2 c WEEK	WEEK
2 c WEEK 	WEEK
2 c WEEK	WEEK
3 d WEEK	ERR
3 d DAY		ERR
3 a WEEK	ERR
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;thanks for all&lt;/P&gt;</description>
    <pubDate>Tue, 07 Jan 2020 17:22:04 GMT</pubDate>
    <dc:creator>ger15xxhcker</dc:creator>
    <dc:date>2020-01-07T17:22:04Z</dc:date>
    <item>
      <title>if all the values in the same by a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-all-the-values-in-the-same-by-a-group/m-p/615725#M180129</link>
      <description>&lt;P&gt;Hi all!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ' d like to know , all the values in a group (group=id1 and id2) is the same or not.&lt;/P&gt;&lt;P&gt;if id=1 and id2=a then FREQ = MONTH and DAY then 'ERR'. if all the same in the group then FREQ='ERR'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sample:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id1 $1. id2 $1. FREQ $5. ;
cards;
0 w YEAR
1 a	MONTH
1 a MONTH
1 a DAY
1 a DAY
1 a DAY
1 b MONTH
2 c WEEK
2 c WEEK
2 c WEEK
3 d WEEK
3 d DAY
3 a WEEK
;
run;

data want;
input id1 $1. id2 $1. FREQ $5. FLAG $5.;
cards;
0 w YEAR 	YEAR
1 a	MONTH	ERR
1 a MONTH	ERR
1 a DAY		ERR
1 a DAY 	ERR
1 a DAY 	ERR
1 b MONTH	MONTH
2 c WEEK	WEEK
2 c WEEK 	WEEK
2 c WEEK	WEEK
3 d WEEK	ERR
3 d DAY		ERR
3 a WEEK	ERR
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;thanks for all&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 17:22:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-all-the-values-in-the-same-by-a-group/m-p/615725#M180129</guid>
      <dc:creator>ger15xxhcker</dc:creator>
      <dc:date>2020-01-07T17:22:04Z</dc:date>
    </item>
    <item>
      <title>Re: if all the values in the same by a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-all-the-values-in-the-same-by-a-group/m-p/615741#M180136</link>
      <description>&lt;P&gt;SQL is good for this one, since it re-merges automatically and you can use MAX/MIN on a character column. If the maximum is different from the minimum you have different values so your flag is ERR.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise the flag is set to the FREQ value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select *, 
      case when max(freq) ne min(freq) then 'ERR'
         else FREQ 
      end as FLAG
from have
group by id1, id2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/192091"&gt;@ger15xxhcker&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I ' d like to know , all the values in a group (group=id1 and id2) is the same or not.&lt;/P&gt;
&lt;P&gt;if id=1 and id2=a then FREQ = MONTH and DAY then 'ERR'. if all the same in the group then FREQ='ERR'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sample:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id1 $1. id2 $1. FREQ $5. ;
cards;
0 w YEAR
1 a	MONTH
1 a MONTH
1 a DAY
1 a DAY
1 a DAY
1 b MONTH
2 c WEEK
2 c WEEK
2 c WEEK
3 d WEEK
3 d DAY
3 a WEEK
;
run;

data want;
input id1 $1. id2 $1. FREQ $5. FLAG $5.;
cards;
0 w YEAR 	YEAR
1 a	MONTH	ERR
1 a MONTH	ERR
1 a DAY		ERR
1 a DAY 	ERR
1 a DAY 	ERR
1 b MONTH	MONTH
2 c WEEK	WEEK
2 c WEEK 	WEEK
2 c WEEK	WEEK
3 d WEEK	ERR
3 d DAY		ERR
3 a WEEK	ERR
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;thanks for all&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 18:27:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-all-the-values-in-the-same-by-a-group/m-p/615741#M180136</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-07T18:27:31Z</dc:date>
    </item>
  </channel>
</rss>

