<?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: elegant way to format percent outputs in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/elegant-way-to-format-percent-outputs/m-p/131848#M35843</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could do this more compactly as folows :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;create table want as&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;select &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; class, &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; catt(ncCount, " (", put(100*ncCount/sum(ncCount), 5.1), ")") as nc&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;from (select class, type, count(*) as ncCount from new group by class, type)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;group by class;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 11 Mar 2013 01:51:17 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2013-03-11T01:51:17Z</dc:date>
    <item>
      <title>elegant way to format percent outputs</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/elegant-way-to-format-percent-outputs/m-p/131847#M35842</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi guys, anyone can help me to simplify my code in the way to format my final dataset want?...maybe using loops rather than write down by hand the 4 combinations (class/type)?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data new;&lt;/P&gt;&lt;P&gt;input name&amp;nbsp; class $ type $;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 a yes&lt;/P&gt;&lt;P&gt;2 a no&lt;/P&gt;&lt;P&gt;3 a yes&lt;/P&gt;&lt;P&gt;4 b no&lt;/P&gt;&lt;P&gt;5 b yes&lt;/P&gt;&lt;P&gt;6 a&amp;nbsp; yes&lt;/P&gt;&lt;P&gt;7 b no&lt;/P&gt;&lt;P&gt;8 b no&lt;/P&gt;&lt;P&gt;9 b yes&lt;/P&gt;&lt;P&gt;10 a yes&lt;/P&gt;&lt;P&gt;11 a yes&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;*creating macrovariables;&lt;BR /&gt;&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;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;select count(distinct name) into: safea&lt;/P&gt;&lt;P&gt;from new&lt;/P&gt;&lt;P&gt;where class='a';&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;select count(distinct name) into: safeb&lt;/P&gt;&lt;P&gt;from new&lt;/P&gt;&lt;P&gt;where class='b';&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;safea;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;safeb;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;create table test as&lt;/P&gt;&lt;P&gt;select distinct class, type, count(distinct name) as n&lt;/P&gt;&lt;P&gt;from new&lt;/P&gt;&lt;P&gt;group by class,type;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*creating the format of my want dataset;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set test;&lt;/P&gt;&lt;P&gt;if class='a' and type='yes' then nc=put(n,best12.)||'('||put(n/&amp;amp;safea*100,5.1)||')';&lt;/P&gt;&lt;P&gt;if class='a' and type='no' then nc=put(n,best12.)||'('||put(n/&amp;amp;safea*100,5.1)||')';&lt;/P&gt;&lt;P&gt;if class='b' and type='yes' then nc=put(n,best12.)||'('||put(n/&amp;amp;safeb*100,5.1)||')';&lt;/P&gt;&lt;P&gt;if class='b' and type='no' then nc=put(n,best12.)||'('||put(n/&amp;amp;safeb*100,5.1)||')';&lt;/P&gt;&lt;P&gt;drop n;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;V.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Mar 2013 00:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/elegant-way-to-format-percent-outputs/m-p/131847#M35842</guid>
      <dc:creator>michtka</dc:creator>
      <dc:date>2013-03-11T00:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: elegant way to format percent outputs</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/elegant-way-to-format-percent-outputs/m-p/131848#M35843</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could do this more compactly as folows :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;create table want as&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;select &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; class, &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; catt(ncCount, " (", put(100*ncCount/sum(ncCount), 5.1), ")") as nc&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;from (select class, type, count(*) as ncCount from new group by class, type)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;group by class;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Mar 2013 01:51:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/elegant-way-to-format-percent-outputs/m-p/131848#M35843</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-03-11T01:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: elegant way to format percent outputs</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/elegant-way-to-format-percent-outputs/m-p/131849#M35844</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I prefer using procedures, such as proc freq.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;SPAN style="color: #011993;"&gt;proc&lt;/SPAN&gt; &lt;SPAN style="color: #011993;"&gt;sort&lt;/SPAN&gt; &lt;SPAN style="color: #0433ff;"&gt;data&lt;/SPAN&gt;=new; &lt;SPAN style="color: #0433ff;"&gt;by&lt;/SPAN&gt; class type;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #0433ff;"&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;SPAN style="color: #011993;"&gt;proc&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #011993;"&gt;freq&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;data&lt;SPAN style="color: #000000;"&gt;=new &lt;/SPAN&gt;noprint&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;SPAN style="color: #0433ff;"&gt;by&lt;/SPAN&gt; class;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;SPAN style="color: #0433ff;"&gt;table&lt;/SPAN&gt; type/&lt;SPAN style="color: #0433ff;"&gt;out&lt;/SPAN&gt;=want1 &lt;SPAN style="color: #0433ff;"&gt;totpct&lt;/SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #011993;"&gt;&lt;SPAN style="font-size: 12pt;"&gt;run&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;SPAN style="color: #011993;"&gt;data&lt;/SPAN&gt; want2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 12pt;"&gt;&amp;nbsp; &lt;SPAN style="color: #0433ff;"&gt;set&lt;/SPAN&gt; want1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 12pt;"&gt;&amp;nbsp; nc=cat(&lt;SPAN style="color: #942193;"&gt;""&lt;/SPAN&gt;, trim(strip(put(count, &lt;SPAN style="color: #009193;"&gt;8.&lt;/SPAN&gt;))), &lt;SPAN style="color: #942193;"&gt;"("&lt;/SPAN&gt;,trim(strip(put(percent/&lt;SPAN style="color: #009193;"&gt;100&lt;/SPAN&gt;, &lt;SPAN style="color: #009193;"&gt;percent8.1&lt;/SPAN&gt;))), &lt;SPAN style="color: #942193;"&gt;")"&lt;/SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #011993;"&gt;&lt;SPAN style="font-size: 12pt;"&gt;run&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Mar 2013 01:57:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/elegant-way-to-format-percent-outputs/m-p/131849#M35844</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-03-11T01:57:18Z</dc:date>
    </item>
    <item>
      <title>Re: elegant way to format percent outputs</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/elegant-way-to-format-percent-outputs/m-p/131850#M35845</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just Brilliant, Thank you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Mar 2013 02:08:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/elegant-way-to-format-percent-outputs/m-p/131850#M35845</guid>
      <dc:creator>michtka</dc:creator>
      <dc:date>2013-03-11T02:08:25Z</dc:date>
    </item>
  </channel>
</rss>

