<?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: Transformation from counts to percentages in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transformation-from-counts-to-percentages/m-p/309422#M66543</link>
    <description>Thanks for your time and assistance!</description>
    <pubDate>Fri, 04 Nov 2016 21:16:36 GMT</pubDate>
    <dc:creator>buechler66</dc:creator>
    <dc:date>2016-11-04T21:16:36Z</dc:date>
    <item>
      <title>Transformation from counts to percentages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-from-counts-to-percentages/m-p/305715#M65237</link>
      <description>&lt;P&gt;Hi. I have a dataset with a single record. It contains a count for each column. I need to output another dataset with one record, like this one, but that has Percentage for each day (and NULL) column instead of a count. Can anyone advise me on creating this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;TOTAL	    _08_01_2016	    _07_30_2016	     _07_29_2016     NULL
1917462	    61	            4813	     18477	     118420&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Oct 2016 17:17:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-from-counts-to-percentages/m-p/305715#M65237</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2016-10-19T17:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation from counts to percentages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-from-counts-to-percentages/m-p/305720#M65239</link>
      <description>&lt;P&gt;Wide data is always a bit annoying to deal with&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Declare two arrays, one for counts and one for percentages&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array cts(*) _date_vars list;&lt;/P&gt;
&lt;P&gt;array pcts(*) day1-day3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Loop over array to calculate percentages&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do I= 1 to dim(cts);&lt;/P&gt;
&lt;P&gt;pcts(I)=cts(I) / total ;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 17:37:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-from-counts-to-percentages/m-p/305720#M65239</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-19T17:37:08Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation from counts to percentages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-from-counts-to-percentages/m-p/305758#M65256</link>
      <description>&lt;P&gt;Thanks for the suggestion. I should've mentioned the number of days (&lt;SPAN&gt;day1-day3) is not static. It may vary from run to run. Can I handle that in some way? &amp;nbsp;Also, what about handling the NULL variable?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 20:03:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-from-counts-to-percentages/m-p/305758#M65256</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2016-10-19T20:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation from counts to percentages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-from-counts-to-percentages/m-p/305759#M65257</link>
      <description>&lt;P&gt;Do you have a naming convention for the variables?&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 20:04:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-from-counts-to-percentages/m-p/305759#M65257</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-19T20:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation from counts to percentages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-from-counts-to-percentages/m-p/305761#M65258</link>
      <description>&lt;P&gt;All the variables except NULL are named like a date with an underscore in front. Like&amp;nbsp;&lt;CODE class="  language-sas"&gt;_07_29_2016.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 20:07:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-from-counts-to-percentages/m-p/305761#M65258</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2016-10-19T20:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation from counts to percentages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-from-counts-to-percentages/m-p/305764#M65260</link>
      <description>&lt;P&gt;I create the above dataset using this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* RULE: MATCHING + NO SCORE IMPACTING. Calculate the totals for this rule and then append this record to FinalData&amp;amp;QTR */
proc means data=QueryData&amp;amp;ZIP5 sum;
var total _: null;
output out=cal_sums&amp;amp;ZIP5 (drop=_type_ _freq_) sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see it creates the _date looking variables (&lt;CODE class="  language-sas"&gt;_08_01_2016)&lt;/CODE&gt;&amp;nbsp;using the _: wildcard on the VAR statement. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt; total _: null&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way to create a dataset of Percentages in a similar way?&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 20:15:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-from-counts-to-percentages/m-p/305764#M65260</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2016-10-19T20:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation from counts to percentages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-from-counts-to-percentages/m-p/305769#M65262</link>
      <description>&lt;P&gt;null is a bad variable name, as it has other context within databases and programming.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the _: wildcard, but you will need to know the amount of variables to do the percentages.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Storing the dates in your variable names isn't a good idea and violates best practices.&lt;/P&gt;
&lt;P&gt;Here's a good article on managing data, from an R perspective but it holds.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.jstatsoft.org/article/view/v059i10" target="_blank"&gt;https://www.jstatsoft.org/article/view/v059i10&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would *seriously* consider tranpsosing your data to a long format, doing your calculations and then retransposing if required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise, determine the number of days needed for percent by querying the sashelp.vcolumn table and storing that number in a macro variable. That can be used to index your arrays.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select count(*) into :count_vars
from sashelp.vcolumn where upper(libname)='WORK' and upper(memname) = 'HAVE' and name like '_%';
quit;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array cts(*) _: null;
array pcts(*) pct1-pct&amp;amp;count_vars pct_null;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The rest of the code is the same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 20:19:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-from-counts-to-percentages/m-p/305769#M65262</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-19T20:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation from counts to percentages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-from-counts-to-percentages/m-p/305777#M65269</link>
      <description>&lt;P&gt;I will give this a shot. Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 20:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-from-counts-to-percentages/m-p/305777#M65269</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2016-10-19T20:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation from counts to percentages</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-from-counts-to-percentages/m-p/309422#M66543</link>
      <description>Thanks for your time and assistance!</description>
      <pubDate>Fri, 04 Nov 2016 21:16:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-from-counts-to-percentages/m-p/309422#M66543</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2016-11-04T21:16:36Z</dc:date>
    </item>
  </channel>
</rss>

