<?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: Proc freq with multiple variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-freq-with-multiple-variables/m-p/874466#M345501</link>
    <description>&lt;P&gt;Try this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods select none;
ods output onewayfreqs=temp;
proc freq data=icd10_06_15;
table diag1--diag12;
run;
ods select all;

*Format output;
data temp2;
length variable $32. variable_value $50.;
set temp;
Variable=scan(table, 2);

Variable_Value=strip(trim(vvaluex(variable)));

keep variable variable_value frequency percent cum:;
label variable='Variable' 
    variable_value='Variable Value';
run;

*Display;
proc print data=temp2(obs=20) label;
run;

proc freq data=temp2;
table value / out=ao;
weight frequency;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;Use PROC FREQ to generate summary for each variable into a table&lt;/LI&gt;
&lt;LI&gt;Use a Data Step to clean up the format of the output data to make it easier to summarize&lt;/LI&gt;
&lt;LI&gt;Summarize it again to get the diagnosises overall, regardless of code&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Not sure if you need temp2 or ao as your output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: This solution does not handle the case where you may have a diagnosis multiple times for a single individual in a single row.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 08 May 2023 15:16:47 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2023-05-08T15:16:47Z</dc:date>
    <item>
      <title>Proc freq with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-freq-with-multiple-variables/m-p/874381#M345469</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to print multiple variables generated from my proc freq so that I can choose the first 20 highest row. I am attempting to use macro but am not getting the expected results. This is my code without macro&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc freq data=icd10_06_15 order=freq noprint;
table diag1--diag12/ out=ao nocum nocol;
proc print data=ao (obs=20) noobs;
run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Code with macro&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro around(start_diag=,end_diag=);
    %do diag=&amp;amp;start_diag %to &amp;amp;end_diag;
        proc freq data=icd10_06_15 order=freq noprint;
 table diag1--diag12/ out=ao nocum nocol;
        run;
    %end;
%mend;
%around(start_diag=1,end_diag=12)
;&lt;BR /&gt;proc print data=ao (obs=20) noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In my output, sas did not generate the diag1-diag11 but it only generate diag12 but I want all the diag variable from diag1 to diag12 in my output dataset AO so I can use proc print to select the first 20 obs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 04:05:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-freq-with-multiple-variables/m-p/874381#M345469</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2023-05-08T04:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: Proc freq with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-freq-with-multiple-variables/m-p/874382#M345470</link>
      <description>&lt;P&gt;Why do you have 12 diagnosis variables, instead of one diagnosis variable with multiple observations per subject?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 04:45:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-freq-with-multiple-variables/m-p/874382#M345470</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-08T04:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: Proc freq with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-freq-with-multiple-variables/m-p/874441#M345487</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; this is how the data is set up&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 12:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-freq-with-multiple-variables/m-p/874441#M345487</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2023-05-08T12:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: Proc freq with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-freq-with-multiple-variables/m-p/874460#M345497</link>
      <description>Then I suggest you transpose to a long layout first before continuing with your analysis.</description>
      <pubDate>Mon, 08 May 2023 14:26:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-freq-with-multiple-variables/m-p/874460#M345497</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-08T14:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: Proc freq with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-freq-with-multiple-variables/m-p/874463#M345498</link>
      <description>&lt;P&gt;Your macro is just generating this code 12 times:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=icd10_06_15 order=freq noprint;
table diag1--diag12/ out=ao nocum nocol;
proc print data=ao (obs=20) noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When you run the PROC FREQ step, it only generates one output dataset ao with the frequency diag12, because that is the way the OUT= option works on the table statement.&amp;nbsp; You only get one output dataset, for the last table specified.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use the macro language to generate a step with 12 table statements like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=icd10_06_15 order=freq noprint;
table diag1/ out=ao1 nocum nocol;
table diag2/ out=ao2 nocum nocol;
table diag3/ out=ao3 nocum nocol;
/*... */
run;

data a0;
  set a01-a012;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you still end up with 12 variables in ao with the count of each diagnosis variables.&amp;nbsp; If you were happy with that, you don't need a macro, you could use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods output OneWayFreqs=ao ;
proc freq data=have order=freq ;
  table diag1-diag12/ out=ao1 nocum nocol;
run ;
ods output close ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;mentioned, if you transpose your data first to a long format, you will make this task, and many more, much much easier.&amp;nbsp; One of the great strengths of SAS is that it makes it easy to reshape data into a format that makes data analysis easier.&amp;nbsp; While many times people think in terms of "one row per patient," if you use this sort of data structure, the coding becomes much more time consuming and error-prone.&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 14:48:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-freq-with-multiple-variables/m-p/874463#M345498</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-05-08T14:48:04Z</dc:date>
    </item>
    <item>
      <title>Re: Proc freq with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-freq-with-multiple-variables/m-p/874466#M345501</link>
      <description>&lt;P&gt;Try this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods select none;
ods output onewayfreqs=temp;
proc freq data=icd10_06_15;
table diag1--diag12;
run;
ods select all;

*Format output;
data temp2;
length variable $32. variable_value $50.;
set temp;
Variable=scan(table, 2);

Variable_Value=strip(trim(vvaluex(variable)));

keep variable variable_value frequency percent cum:;
label variable='Variable' 
    variable_value='Variable Value';
run;

*Display;
proc print data=temp2(obs=20) label;
run;

proc freq data=temp2;
table value / out=ao;
weight frequency;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;Use PROC FREQ to generate summary for each variable into a table&lt;/LI&gt;
&lt;LI&gt;Use a Data Step to clean up the format of the output data to make it easier to summarize&lt;/LI&gt;
&lt;LI&gt;Summarize it again to get the diagnosises overall, regardless of code&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Not sure if you need temp2 or ao as your output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: This solution does not handle the case where you may have a diagnosis multiple times for a single individual in a single row.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 15:16:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-freq-with-multiple-variables/m-p/874466#M345501</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-08T15:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc freq with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-freq-with-multiple-variables/m-p/874467#M345502</link>
      <description>&lt;P&gt;You would have to generate separate TABLES statements and separate output dataset names.&lt;/P&gt;
&lt;P&gt;If you want the DIAG1 to DIAG12 to end up in the same variable in the output then use the RENAME= dataset option when making the datasets.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro around(start_diag=,end_diag=);
proc freq data=icd10_06_15 ;
%do diag=&amp;amp;start_diag %to &amp;amp;end_diag;
  table diag&amp;amp;diag / out=ao&amp;amp;diag(rename=(diag&amp;amp;diag=diag)) noprint;
%end;
run;
data ao_list ;
  set ao&amp;amp;start_diag - so&amp;amp;end_diag ;
  by diag;
run;
proc summary data=ao_list ;
  by diag ;
  output out=ao sum(count)=count;
run;
proc sort data=ao;
  by descending count;
run;
%mend;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that if the same subject has the same diagnosis listed under more than one of the DIAGx columns then that subject will be counted more than once.&lt;/P&gt;
&lt;P&gt;To get unique subject counts first transpose the data and then eliminate the duplicates before counting.&amp;nbsp; You will need a set of BY variables that uniquely identifies the observations in the original dataset.&amp;nbsp; Let's assume that variable is ID.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=icd10_06_15 out=tall(rename=(col1=diag);
  by id;
  var diag1-diag12 ;
run;

proc sort data=tall nodupkey;
  by id diag;
run;

proc freq data=tall order=freq ;
  tables diag / noprint out=ao ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 May 2023 15:18:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-freq-with-multiple-variables/m-p/874467#M345502</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-08T15:18:48Z</dc:date>
    </item>
  </channel>
</rss>

