<?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: Macro for Proc Freq with several variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/887419#M350593</link>
    <description>&lt;PRE&gt;data example;
   infile datalines dlm=',' dsd missover;
   input hosp $ org $ ampicillin $ penem $ amikacin $ ;
datalines;
GG,Strep,NT,10,35
GG,Acine,NT,0,
GG,bacter,,0
CC,bacter,NT,0
CC,kleb,34,NT
GG,kleb,0,NT,0
GG,ecoli,12,NT
CC,strep,0,NT,0
CC,ecoli,377,NT
CC,acine,NT,4,29
GG,citro,,NT
CC,citro,NT,0
CC,amin,45,NT
CC,protius,NT,99,55
GG,protius,0,67,188
CC,serratia,4,,74
GG,serratia,8,102,
; &lt;/PRE&gt;&lt;P&gt;Hi ballardw,&lt;/P&gt;&lt;P&gt;I added a sample of the dataset. The code that you provided works perfectly but I was just wondering if I can get variable values for each hospital and each org as well. For example count of 'NT' in 'penem' for 'CC' and 'ecoli', count of 'NT' in 'penem' for 'CC' and 'Strep'...&lt;/P&gt;&lt;P&gt;Thanks a lot for your help.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Aug 2023 02:22:28 GMT</pubDate>
    <dc:creator>mayasak</dc:creator>
    <dc:date>2023-08-02T02:22:28Z</dc:date>
    <item>
      <title>Macro for Proc Freq with several variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/887394#M350586</link>
      <description>&lt;P&gt;I have a dataset with a big number of variables and I need to find counts of values of 'NT', '0', and ' ', in each of these variables. I've used this so far for one variable at a time :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc freq data = Gn;
tables /*hospital * amikacin_it/norow nocol nopercent;
where amikacin_it in ('NT', '0', ' ');
run;

proc freq data = Gn;
tables /*hospital * ampicillin_it/norow nocol nopercent;
where ampicillin_it in ('NT', '0', ' ');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;......so on and so forth using other variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this takes forever and gives a huge number of tables.&lt;/P&gt;&lt;P&gt;I'm trying to do this using a macro but have no idea how to proceed.&lt;/P&gt;&lt;P&gt;I really appreciate any help.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 21:57:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/887394#M350586</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2023-08-01T21:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for Proc Freq with several variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/887397#M350587</link>
      <description>If you are willing to add a 4th category (call it "other"), you can do this with a short program that doesn't require macros.  Does that sound promising?</description>
      <pubDate>Tue, 01 Aug 2023 22:11:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/887397#M350587</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-08-01T22:11:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for Proc Freq with several variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/887398#M350588</link>
      <description>&lt;P&gt;I'm not sure how this works. Does this cover all other variables? I'm open to any short program, doesn't have to be Macro.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 22:26:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/887398#M350588</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2023-08-01T22:26:17Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for Proc Freq with several variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/887400#M350589</link>
      <description>It would cover any variables you list in the TABLES statement.   You would have the option to use this trick if you want all character variables:&lt;BR /&gt;tables _character_;&lt;BR /&gt;&lt;BR /&gt;There are other tricks that might apply if you want nearly all character variables.</description>
      <pubDate>Tue, 01 Aug 2023 22:23:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/887400#M350589</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-08-01T22:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for Proc Freq with several variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/887402#M350590</link>
      <description>&lt;P&gt;This sounds good but how to get only freqs for only "NT", "0" and " " values (since there are lots of values in each variable) I only want those with no tests done.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 22:31:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/887402#M350590</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2023-08-01T22:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for Proc Freq with several variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/887403#M350591</link>
      <description>&lt;P&gt;It might help to show what you expect the output for a given example input set (hint hint) would look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you don't show anything resembling an output I am not sure what you may expect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My approach to creating a report about such:&lt;/P&gt;
&lt;PRE&gt;data example;
   infile datalines dlm=',' dsd missover;
   input hosp $ var1 $ var2 $ var3 $ ;
datalines;
GG,NT,A,B
GG,NT,0,
GG,NT,,0
CC,0,NT,0
CC,B,NT
GG,0,NT,0
GG,B,NT
CC,0,NT,0
CC,B,NT
CC,NT,A,B
GG,,NT
CC,,NT,0
CC,B,NT
CC,NT,A,B
CC,0,A,B
CC,c,,B
CC,c,A,
;

data reshape;
   set example;
   array v (*) var1 var2 var3;
   do i=1 to dim(v);
      varname = vname(v[i]);
      value = v[i];
      if value in ('NT' '0' '') then output;
   end;
   keep hosp varname value;
run;

Proc tabulate data=reshape;
   class hosp varname;
   class value/missing;
   table hosp,
         varname=' '*value=' '*n='Count'
         /misstext='0'
   ;
run;&lt;/PRE&gt;
&lt;P&gt;The first data step is to provide something with a variety of values.&lt;/P&gt;
&lt;P&gt;The second reshapes the data so that you only have three variables to worry about, the hosp, varname containing the name of the original variable and the value of the variable. The second data step besides reshaping only writes out the values stated to be of interest. Some uncommon items: Use of the Vname function to return the name of a variable from an array element. If you have not seen the IN operator it is a way to examine a variable to see if it has any of the listed values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: If your variables are a mix of data types you can't mix them in an array definition and a different approach would be needed depending on what the final result needs to look like.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 22:45:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/887403#M350591</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-01T22:45:29Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for Proc Freq with several variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/887419#M350593</link>
      <description>&lt;PRE&gt;data example;
   infile datalines dlm=',' dsd missover;
   input hosp $ org $ ampicillin $ penem $ amikacin $ ;
datalines;
GG,Strep,NT,10,35
GG,Acine,NT,0,
GG,bacter,,0
CC,bacter,NT,0
CC,kleb,34,NT
GG,kleb,0,NT,0
GG,ecoli,12,NT
CC,strep,0,NT,0
CC,ecoli,377,NT
CC,acine,NT,4,29
GG,citro,,NT
CC,citro,NT,0
CC,amin,45,NT
CC,protius,NT,99,55
GG,protius,0,67,188
CC,serratia,4,,74
GG,serratia,8,102,
; &lt;/PRE&gt;&lt;P&gt;Hi ballardw,&lt;/P&gt;&lt;P&gt;I added a sample of the dataset. The code that you provided works perfectly but I was just wondering if I can get variable values for each hospital and each org as well. For example count of 'NT' in 'penem' for 'CC' and 'ecoli', count of 'NT' in 'penem' for 'CC' and 'Strep'...&lt;/P&gt;&lt;P&gt;Thanks a lot for your help.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 02:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/887419#M350593</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2023-08-02T02:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for Proc Freq with several variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/887465#M350616</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
   infile datalines dlm=',' dsd missover;
   input hosp $ org $ ampicillin $ penem $ amikacin $ ;
datalines;
GG,Strep,NT,10,35
GG,Acine,NT,0,
GG,bacter,,0
CC,bacter,NT,0
CC,kleb,34,NT
GG,kleb,0,NT,0
GG,ecoli,12,NT
CC,strep,0,NT,0
CC,ecoli,377,NT
CC,acine,NT,4,29
GG,citro,,NT
CC,citro,NT,0
CC,amin,45,NT
CC,protius,NT,99,55
GG,protius,0,67,188
CC,serratia,4,,74
GG,serratia,8,102,
; 

proc sql;
create table want as
select hosp ,org,
sum(ampicillin in ('NT', '0', ' ')) as ampicillin,
sum(penem in ('NT', '0', ' ')) as penem,
sum(amikacin in ('NT', '0', ' ')) as amikacin
 from example
  group by  hosp ,org;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Aug 2023 11:30:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/887465#M350616</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-08-02T11:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for Proc Freq with several variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/887503#M350637</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/47035"&gt;@mayasak&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;data example;
   infile datalines dlm=',' dsd missover;
   input hosp $ org $ ampicillin $ penem $ amikacin $ ;
datalines;
GG,Strep,NT,10,35
GG,Acine,NT,0,
GG,bacter,,0
CC,bacter,NT,0
CC,kleb,34,NT
GG,kleb,0,NT,0
GG,ecoli,12,NT
CC,strep,0,NT,0
CC,ecoli,377,NT
CC,acine,NT,4,29
GG,citro,,NT
CC,citro,NT,0
CC,amin,45,NT
CC,protius,NT,99,55
GG,protius,0,67,188
CC,serratia,4,,74
GG,serratia,8,102,
; &lt;/PRE&gt;
&lt;P&gt;Hi ballardw,&lt;/P&gt;
&lt;P&gt;I added a sample of the dataset. The code that you provided works perfectly but I was just wondering if I can get variable values for each hospital and each org as well. For example count of 'NT' in 'penem' for 'CC' and 'ecoli', count of 'NT' in 'penem' for 'CC' and 'Strep'...&lt;/P&gt;
&lt;P&gt;Thanks a lot for your help.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you want hosp&amp;nbsp; and org in the output pretty much&amp;nbsp; every place my example has "hosp" you want "hosp org" except in the table statement where you want Hosp*org to nest values of org inside Hosp.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hint: try stuff. Get errors. Try to fix the errors. When you can't then show us what you tried and where you need help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 14:58:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/887503#M350637</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-02T14:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for Proc Freq with several variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/888248#M350958</link>
      <description>Thank you ballardw</description>
      <pubDate>Mon, 07 Aug 2023 22:51:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-Proc-Freq-with-several-variables/m-p/888248#M350958</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2023-08-07T22:51:56Z</dc:date>
    </item>
  </channel>
</rss>

