<?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: Creating a summarizing table from one master table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-summarizing-table-from-one-master-table/m-p/783089#M249656</link>
    <description>&lt;P&gt;data have;&lt;BR /&gt;input Account_id Month Flag1 Flag2 Flag3;&lt;BR /&gt;datalines;&lt;BR /&gt;1 2 0 1 0&lt;BR /&gt;1 3 0 0 1&lt;BR /&gt;1 1 1 0 0&lt;BR /&gt;1 2 0 1 0&lt;BR /&gt;3 2 0 1 0&lt;BR /&gt;10 1 1 0 0&lt;BR /&gt;10 2 0 1 0&lt;BR /&gt;; run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by Account_id;&lt;BR /&gt;retain f1 f2 f3;&lt;BR /&gt;if first.Account_id then do;&lt;BR /&gt;f1=0; f2=0; f3=0;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;if flag1=1 then f1=1;&lt;BR /&gt;if flag2=1 then f2=1;&lt;BR /&gt;if flag3=1 then f3=1;&lt;/P&gt;&lt;P&gt;if last.Account_id;&lt;BR /&gt;drop Flag1 Flag2 Flag3 Month;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 30 Nov 2021 09:43:36 GMT</pubDate>
    <dc:creator>AndreaVianello</dc:creator>
    <dc:date>2021-11-30T09:43:36Z</dc:date>
    <item>
      <title>Creating a summarizing table from one master table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-summarizing-table-from-one-master-table/m-p/783083#M249651</link>
      <description>&lt;P&gt;I have a table of the following schematic form:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 240pt;" border="0" width="320" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="63.8672px" height="20" style="height: 15.0pt; width: 48pt;"&gt;Account_id&lt;/TD&gt;
&lt;TD width="63.7891px" style="width: 48pt;"&gt;Month&lt;/TD&gt;
&lt;TD width="63.6914px" style="width: 48pt;"&gt;Flag1&lt;/TD&gt;
&lt;TD width="63.6914px" style="width: 48pt;"&gt;Flag2&lt;/TD&gt;
&lt;TD width="63.7109px" style="width: 48pt;"&gt;Flag3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="63.8672px" height="20" align="right" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD width="63.7891px" align="right"&gt;2&lt;/TD&gt;
&lt;TD width="63.6914px" align="right"&gt;0&lt;/TD&gt;
&lt;TD width="63.6914px" align="right"&gt;1&lt;/TD&gt;
&lt;TD width="63.7109px" align="right"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="63.8672px" height="20" align="right" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD width="63.7891px" align="right"&gt;3&lt;/TD&gt;
&lt;TD width="63.6914px" align="right"&gt;0&lt;/TD&gt;
&lt;TD width="63.6914px" align="right"&gt;0&lt;/TD&gt;
&lt;TD width="63.7109px" align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="63.8672px" height="20" align="right" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD width="63.7891px" align="right"&gt;1&lt;/TD&gt;
&lt;TD width="63.6914px" align="right"&gt;1&lt;/TD&gt;
&lt;TD width="63.6914px" align="right"&gt;0&lt;/TD&gt;
&lt;TD width="63.7109px" align="right"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="63.8672px" height="20" align="right" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD width="63.7891px" align="right"&gt;2&lt;/TD&gt;
&lt;TD width="63.6914px" align="right"&gt;0&lt;/TD&gt;
&lt;TD width="63.6914px" align="right"&gt;1&lt;/TD&gt;
&lt;TD width="63.7109px" align="right"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="63.8672px" height="20" align="right" style="height: 15.0pt;"&gt;3&lt;/TD&gt;
&lt;TD width="63.7891px" align="right"&gt;2&lt;/TD&gt;
&lt;TD width="63.6914px" align="right"&gt;0&lt;/TD&gt;
&lt;TD width="63.6914px" align="right"&gt;1&lt;/TD&gt;
&lt;TD width="63.7109px" align="right"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="63.8672px" height="20" align="right" style="height: 15.0pt;"&gt;10&lt;/TD&gt;
&lt;TD width="63.7891px" align="right"&gt;1&lt;/TD&gt;
&lt;TD width="63.6914px" align="right"&gt;1&lt;/TD&gt;
&lt;TD width="63.6914px" align="right"&gt;0&lt;/TD&gt;
&lt;TD width="63.7109px" align="right"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="63.8672px" height="20" align="right" style="height: 15.0pt;"&gt;10&lt;/TD&gt;
&lt;TD width="63.7891px" align="right"&gt;2&lt;/TD&gt;
&lt;TD width="63.6914px" align="right"&gt;0&lt;/TD&gt;
&lt;TD width="63.6914px" align="right"&gt;1&lt;/TD&gt;
&lt;TD width="63.7109px" align="right"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;&lt;BR /&gt;Notice we have the same Account_id multiple times due to there has been some activity for different months. So if there is some activity for month 2, then flag2 will be 1. If there is some activity for month 3 then flag3 will be 1 and so on.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Now I would like to extract each account once and see which flags it has.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;So the output would be:&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 192pt;" border="0" width="256" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;Account_id&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Flag1&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Flag2&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Flag3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;3&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;10&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;So from this "summarizing table", we see that Account_id 1 has a 1 on each flag. Account_id 10 has a 1 one flag1 and flag2.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Any advice on how to achieve this? I would need to use either a data step och proc sql since I will do some more transformations on the data later.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;All advice appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Nov 2021 09:13:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-summarizing-table-from-one-master-table/m-p/783083#M249651</guid>
      <dc:creator>SasStatistics</dc:creator>
      <dc:date>2021-11-30T09:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a summarizing table from one master table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-summarizing-table-from-one-master-table/m-p/783089#M249656</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;input Account_id Month Flag1 Flag2 Flag3;&lt;BR /&gt;datalines;&lt;BR /&gt;1 2 0 1 0&lt;BR /&gt;1 3 0 0 1&lt;BR /&gt;1 1 1 0 0&lt;BR /&gt;1 2 0 1 0&lt;BR /&gt;3 2 0 1 0&lt;BR /&gt;10 1 1 0 0&lt;BR /&gt;10 2 0 1 0&lt;BR /&gt;; run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by Account_id;&lt;BR /&gt;retain f1 f2 f3;&lt;BR /&gt;if first.Account_id then do;&lt;BR /&gt;f1=0; f2=0; f3=0;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;if flag1=1 then f1=1;&lt;BR /&gt;if flag2=1 then f2=1;&lt;BR /&gt;if flag3=1 then f3=1;&lt;/P&gt;&lt;P&gt;if last.Account_id;&lt;BR /&gt;drop Flag1 Flag2 Flag3 Month;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Nov 2021 09:43:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-summarizing-table-from-one-master-table/m-p/783089#M249656</guid>
      <dc:creator>AndreaVianello</dc:creator>
      <dc:date>2021-11-30T09:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a summarizing table from one master table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-summarizing-table-from-one-master-table/m-p/783095#M249659</link>
      <description>&lt;P&gt;Use PROC SUMMARY/MEANS for such.&lt;/P&gt;
&lt;P&gt;Using example data provided by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/111695"&gt;@AndreaVianello&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Account_id Month Flag1 Flag2 Flag3;
datalines;
1 2 0 1 0
1 3 0 0 1
1 1 1 0 0
1 2 0 1 0
3 2 0 1 0
10 1 1 0 0
10 2 0 1 0
;

proc summary data=have;
by account_id;
var flag:;
output out=want (drop=_type_ _freq_) max()=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please supply example data in such manner in the future, it makes it much easier for us to develop and test code.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Nov 2021 10:06:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-summarizing-table-from-one-master-table/m-p/783095#M249659</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-30T10:06:28Z</dc:date>
    </item>
  </channel>
</rss>

