<?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 proc surveyfreq ods output, need to display output differently, use transpose? in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/proc-surveyfreq-ods-output-need-to-display-output-differently/m-p/98796#M4964</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a dataset with a weight variable (as well as cluster and strata variables) as shown below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;proc sort data=mydataset;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by response;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;proc surveyfreq data= mydataset;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tables raceethnicity * response&amp;nbsp;&amp;nbsp;&amp;nbsp; /&amp;nbsp;&amp;nbsp; cl&amp;nbsp; row&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strata studystratum;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cluster&amp;nbsp; studycluster;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; weight surveyweight ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ods output crosstabs=tableoutput&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;When I run proc surveyfreq with ods for output, I get the following type of output.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="sas_question_figure1_table.PNG" class="jive-image-thumbnail jive-image" src="https://communities.sas.com/legacyfs/online/3660_sas_question_figure1_table.PNG" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, eventually I will need to display my data as shown below.&amp;nbsp; I already know how to export into Excel the ODS output from proc surveyfreq, and then I can manually copy-and-paste cells to re-order them into this desired layout but that would take forever (and would be prone to lots of keystroke mistakes).&amp;nbsp; I want a simple way to do this in SAS.&amp;nbsp; If a macro is required, that is OK because I am familiar with macros and arrays.&amp;nbsp; But before I try doing it with a macro, I think there is probably another easier option, yes?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="sas_question_figure2_desired_layout.PNG" class="jive-image-thumbnail jive-image" src="https://communities.sas.com/legacyfs/online/3661_sas_question_figure2_desired_layout.PNG" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 07 Jun 2013 01:22:01 GMT</pubDate>
    <dc:creator>Bautista</dc:creator>
    <dc:date>2013-06-07T01:22:01Z</dc:date>
    <item>
      <title>proc surveyfreq ods output, need to display output differently, use transpose?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/proc-surveyfreq-ods-output-need-to-display-output-differently/m-p/98796#M4964</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a dataset with a weight variable (as well as cluster and strata variables) as shown below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;proc sort data=mydataset;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by response;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;proc surveyfreq data= mydataset;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tables raceethnicity * response&amp;nbsp;&amp;nbsp;&amp;nbsp; /&amp;nbsp;&amp;nbsp; cl&amp;nbsp; row&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strata studystratum;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cluster&amp;nbsp; studycluster;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; weight surveyweight ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ods output crosstabs=tableoutput&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;When I run proc surveyfreq with ods for output, I get the following type of output.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="sas_question_figure1_table.PNG" class="jive-image-thumbnail jive-image" src="https://communities.sas.com/legacyfs/online/3660_sas_question_figure1_table.PNG" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, eventually I will need to display my data as shown below.&amp;nbsp; I already know how to export into Excel the ODS output from proc surveyfreq, and then I can manually copy-and-paste cells to re-order them into this desired layout but that would take forever (and would be prone to lots of keystroke mistakes).&amp;nbsp; I want a simple way to do this in SAS.&amp;nbsp; If a macro is required, that is OK because I am familiar with macros and arrays.&amp;nbsp; But before I try doing it with a macro, I think there is probably another easier option, yes?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="sas_question_figure2_desired_layout.PNG" class="jive-image-thumbnail jive-image" src="https://communities.sas.com/legacyfs/online/3661_sas_question_figure2_desired_layout.PNG" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Jun 2013 01:22:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/proc-surveyfreq-ods-output-need-to-display-output-differently/m-p/98796#M4964</guid>
      <dc:creator>Bautista</dc:creator>
      <dc:date>2013-06-07T01:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: proc surveyfreq ods output, need to display output differently, use transpose?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/proc-surveyfreq-ods-output-need-to-display-output-differently/m-p/98797#M4965</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since SAS has decided to not add output datasets options to the survey procs you can use the ODS Output statement to bring the results into a dataset that you can then manipulate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this case I think you want&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ods output crosstabs=mylib.mycrosstabdata;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;surveyfreq code&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ods output close;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It looks like proc tabulate would generate the output you desire excuding the rows with the summaries (response= .);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Jun 2013 15:46:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/proc-surveyfreq-ods-output-need-to-display-output-differently/m-p/98797#M4965</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-06-07T15:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: proc surveyfreq ods output, need to display output differently, use transpose?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/proc-surveyfreq-ods-output-need-to-display-output-differently/m-p/98798#M4966</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Updating my post.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was able to figure-out a solution for this problem, using a macro which pulls specific cells from the proc surveyfreq ods output table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It took me a long tie to create the macro, but eventually I got it done.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the example above, there are 4 possible values for the independent predictor variable "RaceEthnicity" and 5 possible values for the dependent/outcome variable "response."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So in order to create my formatted table, I needed to first understand the following logic.&amp;nbsp; After I did that, it was easy to create a macro based on a series of do/to/end statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="matrix.PNG" class="jive-image-thumbnail jive-image" src="https://communities.sas.com/legacyfs/online/3939_matrix.PNG" width="450" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" jive-data-cell="{&amp;quot;color&amp;quot;:&amp;quot;#575757&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;left&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;NaN&amp;quot;,&amp;quot;backgroundColor&amp;quot;:&amp;quot;transparent&amp;quot;,&amp;quot;fontFamily&amp;quot;:&amp;quot;arial,helvetica,sans-serif&amp;quot;}" jive-data-header="{&amp;quot;color&amp;quot;:&amp;quot;#FFFFFF&amp;quot;,&amp;quot;backgroundColor&amp;quot;:&amp;quot;#6690BC&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;center&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;2&amp;quot;}"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD style="color: #575757; text-align: left; padding: 10px; background-color: transparent; font-family: arial, helvetica, sans-serif; vertical-align: middle;"&gt;&lt;P&gt;%macro mergetables(indepvariable,outcomevariable,out_tablename,maxrowvals,maxcolvals,tablenum);&lt;/P&gt;&lt;P&gt;%let currentcolval=1;&lt;/P&gt;&lt;P&gt;%do currentcolval = 1 %to &amp;amp;maxcolvals ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; data merged_col&amp;amp;currentcolval&amp;amp;outcomevariable;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let string2 = &amp;amp;outcomevariable&amp;amp;currentcolval;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set %do currentrow=1 %to %eval(&amp;amp;maxrowvals +1); &amp;amp;string2&amp;amp;currentrow %end; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp; proc datasets;&lt;/P&gt;&lt;P&gt;&amp;nbsp; delete %do currentrow=1 %to %eval(&amp;amp;maxrowvals +1); &amp;amp;string2&amp;amp;currentrow %end; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let currentcolval=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; data pre&amp;amp;tablenum&amp;amp;outcomevariable&amp;amp;indepvariable;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge %do currentcolval=1 %to&amp;nbsp; &amp;amp;maxcolvals ; merged_col&amp;amp;currentcolval&amp;amp;outcomevariable %end; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by F_&amp;amp;indepvariable; &lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp; proc datasets;&lt;/P&gt;&lt;P&gt;&amp;nbsp; delete %do currentcolval=1 %to &amp;amp;maxcolvals ; merged_col&amp;amp;currentcolval&amp;amp;outcomevariable %end; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let currentrowval=1;&lt;/P&gt;&lt;P&gt;data&amp;nbsp; &amp;amp;tablenum&amp;amp;outcomevariable&amp;amp;indepvariable;&lt;/P&gt;&lt;P&gt;merge pre&amp;amp;tablenum&amp;amp;outcomevariable&amp;amp;indepvariable %do currentrowval=1 %to %eval(&amp;amp;maxrowvals +1); &lt;/P&gt;&lt;P&gt;For_n_of_row&amp;amp;currentrowval %end; ;&lt;/P&gt;&lt;P&gt;by F_&amp;amp;indepvariable;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*&amp;nbsp; EXPORT THE DATASET '&amp;amp;tablenum&amp;amp;outcomevariable&amp;amp;indepvariable' saved as '&amp;amp;tablenum&amp;amp;out_tablename' */&lt;/P&gt;&lt;P&gt;PROC EXPORT DATA=WORK.&amp;amp;tablenum&amp;amp;outcomevariable&amp;amp;indepvariable &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OUTFILE= "C:\Documents and Settings\user\Desktop\save_exports\&amp;amp;tablenum&amp;amp;out_tablename" &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DBMS=EXCEL5 REPLACE;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*&amp;nbsp; EXPORT THE DATASET of proc surveyfreq statistics '&amp;amp;out_tablename' */&lt;/P&gt;&lt;P&gt;PROC EXPORT DATA=WORK.&amp;amp;out_tablename &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OUTFILE= "C:\Documents and Settings\gjbautista\Desktop\save_exports\psfd\&amp;amp;tablenum&amp;amp;out_tablename" &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DBMS=EXCEL5 REPLACE;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let currentrowval=1;&lt;/P&gt;&lt;P&gt;proc datasets;&lt;/P&gt;&lt;P&gt;delete pre&amp;amp;tablenum&amp;amp;outcomevariable&amp;amp;indepvariable %do currentrowval=1 %to %eval(&amp;amp;maxrowvals +1); &lt;/P&gt;&lt;P&gt;For_n_of_row&amp;amp;currentrowval %end; ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend mergetables;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*&amp;nbsp;&amp;nbsp; Call the macro&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;/P&gt;&lt;P&gt;%mergetables(raceethnicity,response,T_01_psfd_racexresponse,4,5,T_01);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Jul 2013 18:15:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/proc-surveyfreq-ods-output-need-to-display-output-differently/m-p/98798#M4966</guid>
      <dc:creator>Bautista</dc:creator>
      <dc:date>2013-07-25T18:15:04Z</dc:date>
    </item>
  </channel>
</rss>

