<?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: Case Statement + Group By in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Group-By/m-p/825586#M326090</link>
    <description>&lt;P&gt;So if you have two observations per group you can just build the new string from the MIN and MAX values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table diff_answer_combos as
select ssn
    , count(*) as nobs
    , catx('+',min(status_flg),max(status_flg)) as status_combined length=5
from duplicates_diff_answer
group by ssn
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 27 Jul 2022 03:32:03 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-07-27T03:32:03Z</dc:date>
    <item>
      <title>Case Statement + Group By</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Group-By/m-p/825543#M326075</link>
      <description>&lt;P&gt;Everyone has more than one result in my dataset. I am trying to create a new column that shows if they answered 1 and 2 OR 1 and 3 OR 1 and 5 OR 3 and 5, etc. &lt;/P&gt;
&lt;P&gt;This is what I currently have, but it is not looking at the data by ssn which is what I need it to do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table diff_answer_combos as
select *
, case  when status_flg in (1,2) then "1+2"
		when status_flg in (1,3) then "1+3"
 		when status_flg in (1,4) then "1+4"
		when status_flg in (1,5) then "1+5"
		when status_flg in (1,6) then "1+6"
		when status_flg in (2,3) then "2+3"
		when status_flg in (2,4) then "2+4"
		when status_flg in (2,5) then "2+5"
		when status_flg in (2,6) then "2+6"
		when status_flg in (3,4) then "3+4"
		when status_flg in (3,5) then "3+5"
		when status_flg in (3,6) then "3+6"
		when status_flg in (4,5) then "4+5"
		when status_flg in (4,6) then "4+6"
		when status_flg in (5,6) then "5+6"
	else ""
end as status_combined

from duplicates_diff_answer
order by ssn;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please help!&lt;/P&gt;
&lt;P&gt;Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 20:39:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Group-By/m-p/825543#M326075</guid>
      <dc:creator>A_Halps</dc:creator>
      <dc:date>2022-07-26T20:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement + Group By</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Group-By/m-p/825544#M326076</link>
      <description>&lt;P&gt;So you will always have exactly two observations per ssn?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 20:46:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Group-By/m-p/825544#M326076</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-07-26T20:46:02Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement + Group By</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Group-By/m-p/825551#M326077</link>
      <description>&lt;P&gt;If you're looking for status_flg across more than one row this type of logic will not work, it only evaluates once per row so I don't think this will achieve what you're looking to accomplish.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you show a sample of input data and desired results?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 20:54:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Group-By/m-p/825551#M326077</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-26T20:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement + Group By</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Group-By/m-p/825586#M326090</link>
      <description>&lt;P&gt;So if you have two observations per group you can just build the new string from the MIN and MAX values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table diff_answer_combos as
select ssn
    , count(*) as nobs
    , catx('+',min(status_flg),max(status_flg)) as status_combined length=5
from duplicates_diff_answer
group by ssn
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Jul 2022 03:32:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Group-By/m-p/825586#M326090</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-27T03:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement + Group By</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Group-By/m-p/825671#M326121</link>
      <description>Correct</description>
      <pubDate>Wed, 27 Jul 2022 13:34:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Group-By/m-p/825671#M326121</guid>
      <dc:creator>A_Halps</dc:creator>
      <dc:date>2022-07-27T13:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement + Group By</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Group-By/m-p/825685#M326123</link>
      <description>&lt;P&gt;Then (IMO) a data step will be your best solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=duplicates_diff_answer;
by ssn status_flg;
run;

data diff_answer_combos;
set duplicates_diff_answer;
by ssn;
if first.ssn
then status_combined = "   "; /* set a sufficient length here, if more is needed */
else status_combined = catx("+",status_combined,status_flg);
if last.ssn;
drop status_flg;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need to make sure that only 2 rows exist per ssn, count the number of plus signs.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 14:26:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Group-By/m-p/825685#M326123</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-07-27T14:26:44Z</dc:date>
    </item>
  </channel>
</rss>

