<?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: Autiomate the Sum(case when ) with macro and arrays in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Autiomate-the-Sum-case-when-with-macro-and-arrays/m-p/874912#M345701</link>
    <description>&lt;P&gt;Actually my total Query is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data cont;&lt;BR /&gt;input ID $ Indi $ date: mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;001 Green 02/23/2001&lt;BR /&gt;001 Black 02/24/2001&lt;BR /&gt;001 Green 03/18/2000&lt;BR /&gt;002 Green 01/19/2021&lt;BR /&gt;002 Green 02/19/2012&lt;BR /&gt;003 Red 01/11/2000&lt;BR /&gt;004 Black 02/12/2021&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table cont as&lt;BR /&gt;select ID,&lt;BR /&gt;sum(case when Indi ="Green" then 1 else 0 end ) as Green_count,&lt;BR /&gt;sum(case when Indi ="Red" then 1 else 0 end ) as Red_count,&lt;BR /&gt;sum(case when Indi ="Black" then 1 else 0 end ) as Black_count,&lt;BR /&gt;sum(case when Indi ="Orange" then 1 else 0 end ) as Orange_count&lt;BR /&gt;from cont&lt;BR /&gt;group by id;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;/* my business some times require a query like this */&lt;/P&gt;&lt;P&gt;data check;&lt;BR /&gt;set cont;&lt;BR /&gt;by id;&lt;BR /&gt;if Green_count&amp;gt; 1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My Question here is like how I am using if condition from the sql results , can i also query the same from proc freq results .&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 10 May 2023 12:46:26 GMT</pubDate>
    <dc:creator>nxmogil</dc:creator>
    <dc:date>2023-05-10T12:46:26Z</dc:date>
    <item>
      <title>Autiomate the Sum(case when ) with macro and arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Autiomate-the-Sum-case-when-with-macro-and-arrays/m-p/874880#M345686</link>
      <description>&lt;P&gt;Hi , I would be using this code very often, please suggest an alternative way to automate it&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data cont;&lt;/P&gt;&lt;P&gt;input Id $ Indi $ date: mmddyy10.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;001 green 02/23/2022&lt;/P&gt;&lt;P&gt;002&amp;nbsp; green 03/21/2022&lt;/P&gt;&lt;P&gt;001 black 04/23/2022&lt;/P&gt;&lt;P&gt;002 breen 06/18/2002&lt;/P&gt;&lt;P&gt;003 brown 05/19/2022&lt;/P&gt;&lt;P&gt;004 Black 08/15/2000&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table indi-count as&amp;nbsp;&lt;/P&gt;&lt;P&gt;select id,&amp;nbsp;&lt;/P&gt;&lt;P&gt;sum(case when&amp;nbsp;Indi = "green" then 1 else 0 end) as green_count,&lt;/P&gt;&lt;P&gt;sum(case when&amp;nbsp;Indi = "black" then 1 else 0 end) as black_count,&lt;/P&gt;&lt;P&gt;sum(case when&amp;nbsp;Indi = "brown" then 1 else 0 end) as brown_count,&lt;/P&gt;&lt;P&gt;from&amp;nbsp;cont&lt;/P&gt;&lt;P&gt;group by id;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 10:15:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Autiomate-the-Sum-case-when-with-macro-and-arrays/m-p/874880#M345686</guid>
      <dc:creator>nxmogil</dc:creator>
      <dc:date>2023-05-10T10:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: Autiomate the Sum(case when ) with macro and arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Autiomate-the-Sum-case-when-with-macro-and-arrays/m-p/874884#M345689</link>
      <description>&lt;P&gt;Do you need the wide format (one record per ID), or do you only need the counts?&amp;nbsp; I would start with PROC FREQ:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=cont ;
  tables id*indi/missing out=want ;
run ;

proc print data=want ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This has the benefit of catching all the typos in the data too. : )&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 10:53:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Autiomate-the-Sum-case-when-with-macro-and-arrays/m-p/874884#M345689</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-05-10T10:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: Autiomate the Sum(case when ) with macro and arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Autiomate-the-Sum-case-when-with-macro-and-arrays/m-p/874887#M345691</link>
      <description>&lt;BR /&gt;Thank you for your quick response&lt;BR /&gt;Yeah I use proc freq some times to but when I want to give a condition that if green_count &amp;gt; 0 , Can I do it with oroc freq results</description>
      <pubDate>Wed, 10 May 2023 11:01:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Autiomate-the-Sum-case-when-with-macro-and-arrays/m-p/874887#M345691</guid>
      <dc:creator>nxmogil</dc:creator>
      <dc:date>2023-05-10T11:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: Autiomate the Sum(case when ) with macro and arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Autiomate-the-Sum-case-when-with-macro-and-arrays/m-p/874895#M345695</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441935"&gt;@nxmogil&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;Yeah I use proc freq some times to but when I want to give a condition that if green_count &amp;gt; 0 , Can I do it with oroc freq results&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't understand this. Please explain further, provide more details.&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 11:42:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Autiomate-the-Sum-case-when-with-macro-and-arrays/m-p/874895#M345695</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-10T11:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: Autiomate the Sum(case when ) with macro and arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Autiomate-the-Sum-case-when-with-macro-and-arrays/m-p/874907#M345699</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441935"&gt;@nxmogil&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;Thank you for your quick response&lt;BR /&gt;Yeah I use proc freq some times to but when I want to give a condition that if green_count &amp;gt; 0 , Can I do it with oroc freq results&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, you could do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=cont ;
  tables id*indi/missing out=want ;
run ;

data want2 ;
  set want ;
  if indi='green' and count&amp;gt;0 ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But for your sample data that would give you same list of IDs as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set cont;
  if Indi='green';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I think it would be helpful if you describe more of the big picture of what you are trying to do.&amp;nbsp; Also, suggest fixing the typos in your sample code to provide example code that runs without errors, and the example output you want.&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 12:25:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Autiomate-the-Sum-case-when-with-macro-and-arrays/m-p/874907#M345699</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-05-10T12:25:17Z</dc:date>
    </item>
    <item>
      <title>Re: Autiomate the Sum(case when ) with macro and arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Autiomate-the-Sum-case-when-with-macro-and-arrays/m-p/874912#M345701</link>
      <description>&lt;P&gt;Actually my total Query is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data cont;&lt;BR /&gt;input ID $ Indi $ date: mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;001 Green 02/23/2001&lt;BR /&gt;001 Black 02/24/2001&lt;BR /&gt;001 Green 03/18/2000&lt;BR /&gt;002 Green 01/19/2021&lt;BR /&gt;002 Green 02/19/2012&lt;BR /&gt;003 Red 01/11/2000&lt;BR /&gt;004 Black 02/12/2021&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table cont as&lt;BR /&gt;select ID,&lt;BR /&gt;sum(case when Indi ="Green" then 1 else 0 end ) as Green_count,&lt;BR /&gt;sum(case when Indi ="Red" then 1 else 0 end ) as Red_count,&lt;BR /&gt;sum(case when Indi ="Black" then 1 else 0 end ) as Black_count,&lt;BR /&gt;sum(case when Indi ="Orange" then 1 else 0 end ) as Orange_count&lt;BR /&gt;from cont&lt;BR /&gt;group by id;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;/* my business some times require a query like this */&lt;/P&gt;&lt;P&gt;data check;&lt;BR /&gt;set cont;&lt;BR /&gt;by id;&lt;BR /&gt;if Green_count&amp;gt; 1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My Question here is like how I am using if condition from the sql results , can i also query the same from proc freq results .&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 12:46:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Autiomate-the-Sum-case-when-with-macro-and-arrays/m-p/874912#M345701</guid>
      <dc:creator>nxmogil</dc:creator>
      <dc:date>2023-05-10T12:46:26Z</dc:date>
    </item>
  </channel>
</rss>

