<?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: Organizar tabela in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758149#M80828</link>
    <description>Do you need counts and percents?&lt;BR /&gt;&lt;BR /&gt;PROC TABULATE (or REPORT) is a better option in this case. &lt;BR /&gt;Tutorial on PROC TABULATE - percentages are slightly harder but you also have more control over it. &lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/faq/how-can-i-create-tables-using-proc-tabulate/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/faq/how-can-i-create-tables-using-proc-tabulate/&lt;/A&gt;</description>
    <pubDate>Thu, 29 Jul 2021 16:29:10 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-07-29T16:29:10Z</dc:date>
    <item>
      <title>Organizar tabela</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758145#M80827</link>
      <description>&lt;P&gt;From the code::&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc freq data=base;&lt;/P&gt;&lt;P&gt;by month;&lt;/P&gt;&lt;P&gt;tables type_client*leaf / out=data1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created the table below, but I need it to have the following variables: month, leaf, count_type_client (if 0), count_type_client (if 1).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That is, I need to separate the variable "type_client"&amp;nbsp;into&amp;nbsp;two columns, if 0&amp;nbsp;and if&amp;nbsp;1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OUTD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lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;23253&lt;/TD&gt;&lt;TD&gt;16.94&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;39683&lt;/TD&gt;&lt;TD&gt;28.91&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;12354&lt;/TD&gt;&lt;TD&gt;9.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;632&lt;/TD&gt;&lt;TD&gt;0.46&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;2044&lt;/TD&gt;&lt;TD&gt;1.49&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;871&lt;/TD&gt;&lt;TD&gt;0.63&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 29 Jul 2021 16:21:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758145#M80827</guid>
      <dc:creator>Thalitacosta</dc:creator>
      <dc:date>2021-07-29T16:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: Organizar tabela</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758149#M80828</link>
      <description>Do you need counts and percents?&lt;BR /&gt;&lt;BR /&gt;PROC TABULATE (or REPORT) is a better option in this case. &lt;BR /&gt;Tutorial on PROC TABULATE - percentages are slightly harder but you also have more control over it. &lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/faq/how-can-i-create-tables-using-proc-tabulate/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/faq/how-can-i-create-tables-using-proc-tabulate/&lt;/A&gt;</description>
      <pubDate>Thu, 29 Jul 2021 16:29:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758149#M80828</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-07-29T16:29:10Z</dc:date>
    </item>
    <item>
      <title>Re: Organizar tabela</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758151#M80829</link>
      <description>&lt;P&gt;Your question is not very clear as to whether by "table" you mean the output data set created by proc freq or a report for people to read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is a report then you need to show what the rest of the columns look like because just adding separate columns for type_client doesn't make much sense. What would be the count and percent on a row?&lt;/P&gt;
&lt;P&gt;If want a header of the client type with the count and % below then that would be Proc Report or tabulate for the report people read but the data set will quite different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if this helps;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc tabulate data=base;
   class month leaf type_client;
  table month*leaf,
          type_client*(n reppctn)
  ;
run;&lt;/PRE&gt;
&lt;P&gt;This will have the count and percent under each level of client.&lt;/P&gt;
&lt;P&gt;There are a number of different percents that can be calculated, row, column, page (if you specify a page dimension before the row of month and leaf)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 16:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758151#M80829</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-29T16:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: Organizar tabela</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758152#M80830</link>
      <description>FYI - if you're not familiar with ODS,  you can use it to have the PROC FREQ output displayed transferred directly to Excel/PDF/Word.&lt;BR /&gt;&lt;BR /&gt;ods pdf file='/home/demo/file.pdf' ;&lt;BR /&gt;proc freq data=sashelp.class;&lt;BR /&gt;table age*sex;&lt;BR /&gt;run;&lt;BR /&gt;ods pdf close;</description>
      <pubDate>Thu, 29 Jul 2021 16:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758152#M80830</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-07-29T16:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: Organizar tabela</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758155#M80831</link>
      <description>&lt;P&gt;Do you want your results to look like this?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1627577249470.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62085iC0E4F57735E45D17/image-size/large?v=v2&amp;amp;px=999" role="button" title="jimbarbour_0-1627577249470.png" alt="jimbarbour_0-1627577249470.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, the below code would work.&amp;nbsp; If you want a SAS dataset instead of HTML, then uncomment the CREATE TABLE portion of the code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	Data1;
	INFILE	DATALINES	DSD	DLM='09'X;
	INPUT
		month	type_client	leaf	count	percent;
DATALINES;
1	0	3	21188	19.59
1	0	5	25208	23.31
1	0	7	7566	6.99
1	1	3	529	0.49
1	1	5	1066	0.98
1	1	7	522	0.48
2	0	3	23253	16.94
2	0	5	39683	28.91
2	0	7	12354	9.00
2	1	3	632	0.46
2	1	5	2044	1.49
2	1	7	871	0.63
;
RUN;

PROC	SQL	;
/*	CREATE	TABLE	Data2	AS*/
	SELECT	
		month	
		,type_client
		,leaf	
		,CASE
			WHEN	(type_client = 0)  THEN	count	
			ELSE	.
			END	AS	Client_0_Count
		,CASE
			WHEN	(type_client = 1)  THEN	count	
			ELSE	.
			END	AS	Client_1_Count
		,percent
		FROM	Data1
		;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 16:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758155#M80831</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-07-29T16:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: Organizar tabela</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758162#M80832</link>
      <description>Perfect! The code helped me.&lt;BR /&gt;&lt;BR /&gt;Sorry for the spelling mistakes, I don't know english, I'm Brazilian.</description>
      <pubDate>Thu, 29 Jul 2021 17:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758162#M80832</guid>
      <dc:creator>Thalitacosta</dc:creator>
      <dc:date>2021-07-29T17:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Organizar tabela</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758164#M80833</link>
      <description>&lt;BLOCKQUOTE&gt;Sorry for the spelling mistakes, I don't know english, I'm Brazilian.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In that case, "Bom dia".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Everything now is "Muito bom" yes?&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 17:15:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758164#M80833</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-07-29T17:15:30Z</dc:date>
    </item>
    <item>
      <title>Re: Organizar tabela</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758167#M80834</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/391297"&gt;@Thalitacosta&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Perfect! The code helped me.&lt;BR /&gt;&lt;BR /&gt;Sorry for the spelling mistakes, I don't know english, I'm Brazilian.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Didn't notice any spelling problem, just a partial description of need.&lt;/P&gt;
&lt;P&gt;Well done for non-English speaker. I know I don't want to discuss such technical things in any of the other languages I have some experience with.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 17:31:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758167#M80834</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-29T17:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: Organizar tabela</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758188#M80835</link>
      <description>&lt;BR /&gt;I used only N:&lt;BR /&gt;&lt;BR /&gt;Proc tabulate data=base;&lt;BR /&gt;class month leaf type_client;&lt;BR /&gt;table month*leaf,&lt;BR /&gt;type_client*n&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;But now I need to add the total (all) at the end of each line (sum of the observations of 0 and 1). So it looks like this:&lt;BR /&gt;type_client&lt;BR /&gt;0 1&lt;BR /&gt;month leaf N N ALL&lt;BR /&gt;1 3 21188 529 21717&lt;BR /&gt;1 5 25208 1066 26274&lt;BR /&gt;</description>
      <pubDate>Thu, 29 Jul 2021 18:02:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758188#M80835</guid>
      <dc:creator>Thalitacosta</dc:creator>
      <dc:date>2021-07-29T18:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: Organizar tabela</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758216#M80838</link>
      <description>&lt;P&gt;You may want to open a new Question for this.&amp;nbsp; It will get more attention since this question is already marked as Solved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 19:04:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Organizar-tabela/m-p/758216#M80838</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-07-29T19:04:09Z</dc:date>
    </item>
  </channel>
</rss>

