<?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 Percent of row total without naming each column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Percent-of-row-total-without-naming-each-column/m-p/739818#M230969</link>
    <description>&lt;P&gt;&lt;BR /&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table that looks like this:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;yrmo&lt;/TD&gt;&lt;TD&gt;Bin&lt;/TD&gt;&lt;TD&gt;Var1&lt;/TD&gt;&lt;TD&gt;Var2&lt;/TD&gt;&lt;TD&gt;Var3&lt;/TD&gt;&lt;TD&gt;Var4&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Row Total&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;202010&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;202010&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;202011&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;27&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;202012&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;26&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This table was generated using proc transpose, and so it's just a simple pivot.&lt;BR /&gt;&lt;BR /&gt;Yrmo is of course Year-Month, Bin is the group, and then Var1 - Var 4 are the types of status' an account is in. Row Total is the total of the Var1-Var4.&lt;BR /&gt;&lt;BR /&gt;What I need to do is get the %'s each value based on the row's total.&amp;nbsp;&lt;BR /&gt;So for example, where yrmo = 202010 and Var1 = 3, it would be 16.67% because 3/18 (18 being the row total) ='s 16.67%.&lt;BR /&gt;&lt;BR /&gt;My problem is that I don't know what Var1 - Var4 will be always, so they can be different each time the program runs depending on the status of an account.&lt;BR /&gt;I know that proc tabulate has an option to compute rowpctn, which is helpful, but I can't name the variables because I don't know what they will be.&lt;BR /&gt;&lt;BR /&gt;Hopefully I explained this well enough, any help is greatly appreciated.&lt;/P&gt;</description>
    <pubDate>Fri, 07 May 2021 16:03:53 GMT</pubDate>
    <dc:creator>hporter</dc:creator>
    <dc:date>2021-05-07T16:03:53Z</dc:date>
    <item>
      <title>Percent of row total without naming each column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-of-row-total-without-naming-each-column/m-p/739818#M230969</link>
      <description>&lt;P&gt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&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;26&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This table was generated using proc transpose, and so it's just a simple pivot.&lt;BR /&gt;&lt;BR /&gt;Yrmo is of course Year-Month, Bin is the group, and then Var1 - Var 4 are the types of status' an account is in. Row Total is the total of the Var1-Var4.&lt;BR /&gt;&lt;BR /&gt;What I need to do is get the %'s each value based on the row's total.&amp;nbsp;&lt;BR /&gt;So for example, where yrmo = 202010 and Var1 = 3, it would be 16.67% because 3/18 (18 being the row total) ='s 16.67%.&lt;BR /&gt;&lt;BR /&gt;My problem is that I don't know what Var1 - Var4 will be always, so they can be different each time the program runs depending on the status of an account.&lt;BR /&gt;I know that proc tabulate has an option to compute rowpctn, which is helpful, but I can't name the variables because I don't know what they will be.&lt;BR /&gt;&lt;BR /&gt;Hopefully I explained this well enough, any help is greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 07 May 2021 16:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-of-row-total-without-naming-each-column/m-p/739818#M230969</guid>
      <dc:creator>hporter</dc:creator>
      <dc:date>2021-05-07T16:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: Percent of row total without naming each column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-of-row-total-without-naming-each-column/m-p/739832#M230980</link>
      <description>IMO, calculate your percentages before your transpose using proc freq and then transpose it together instead.</description>
      <pubDate>Fri, 07 May 2021 16:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-of-row-total-without-naming-each-column/m-p/739832#M230980</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-07T16:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: Percent of row total without naming each column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-of-row-total-without-naming-each-column/m-p/739841#M230986</link>
      <description>&lt;P&gt;You may want to provide an actual example data set of the data before transposing. There are things that can be done with single variables that are much harder when forced into multiple variables.&lt;/P&gt;
&lt;P&gt;Example with a data set you should have available:&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=sashelp.class;
   class sex age;
   tables sex all='All sexes',
          (age all='row total')*(n rowpctn)
   ;
run;&lt;/PRE&gt;
&lt;P&gt;Which &lt;STRONG&gt;might&lt;/STRONG&gt; translate to something like this using the data BEFORE transposing and possibly summarized (you don't say):&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=have;
   class yrmo bin status;
   tables yrmo*bin ,
          (status all='row total')*(n rowpctn)
   ;
run;&lt;/PRE&gt;
&lt;P&gt;This would work for a data set that has yrmo bin and status combinations as one record not a summary data set that looks something like this:&lt;/P&gt;
&lt;PRE&gt;data have;
   input yrmo bin status;
datalines;
1 1 1
1 1 1
2 0 2
2 1 3
1 0 2
1 0 4
3 1 1
3 1 2
3 1 3
;&lt;/PRE&gt;
&lt;P&gt;Hint: a data step like this, pasted into a text or code box opened with the &amp;lt;/&amp;gt; or "running man" icon is the preferred way to show example data so we can write code against something like your data.&lt;/P&gt;
&lt;P&gt;I am too lazy to type out extra stuff so the yrmo values are shorter. The behavior would be the same &lt;STRONG&gt;except&lt;/STRONG&gt; in the case of an actual date value. Then a format assigned to the date value creates the groups.&lt;/P&gt;
&lt;P&gt;Look at the SASHELP.CLASS such as print (there are only 19 records so this is easy).&lt;/P&gt;</description>
      <pubDate>Fri, 07 May 2021 16:54:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-of-row-total-without-naming-each-column/m-p/739841#M230986</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-07T16:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: Percent of row total without naming each column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-of-row-total-without-naming-each-column/m-p/739855#M230993</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/269855"&gt;@hporter&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Probably less elegant in your case, but a general technique for working with variables without knowing their names is to define &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p08do6szetrxe2n136ush727sbuo.htm" target="_blank" rel="noopener"&gt;arrays&lt;/A&gt;. These can be based on "implicit" &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/p0wphcpsfgx6o7n1sjtqzizp1n39.htm" target="_blank" rel="noopener"&gt;variable lists&lt;/A&gt; like &lt;FONT face="courier new,courier"&gt;_numeric_&lt;/FONT&gt;&amp;nbsp;or "explicit" variable lists dynamically created from &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/n02s19q65mw08gn140bwfdh7spx7.htm#n16n2dxxzwmaaen1vc1wun3a8355" target="_blank" rel="noopener"&gt;DICTIONARY.COLUMNS&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input yrmo Bin Var1 Var2 Var3 Var4 Row_Total;
cards;
202010 1 3 5 7 3 18
202010 2 4 4 4 6 18
202011 1 6 6 7 8 27
202012 1 5 6 7 8 26
;

proc sql noprint;
select name, name into :vars separated by ' ', :pvars separated by ' pct_' 
from dictionary.columns
where libname='WORK' &amp;amp; memname='HAVE' &amp;amp; name ~in ('yrmo' 'Bin' 'Row_Total')
order by varnum;
quit;

data want(drop=i);
set have;
array v[*] &amp;amp;vars;
array p[*] pct_&amp;amp;pvars;
do i=1 to dim(v);
  p[i]=divide(v[i],row_total);
end;
format pct_: percent9.2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 May 2021 18:23:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-of-row-total-without-naming-each-column/m-p/739855#M230993</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-05-07T18:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: Percent of row total without naming each column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-of-row-total-without-naming-each-column/m-p/739867#M230995</link>
      <description>&lt;P&gt;Thank you. I did not know about Dictionary.Columns that's going to be useful in the future.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate the help, this worked perfectly for me.&lt;/P&gt;</description>
      <pubDate>Fri, 07 May 2021 19:30:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-of-row-total-without-naming-each-column/m-p/739867#M230995</guid>
      <dc:creator>hporter</dc:creator>
      <dc:date>2021-05-07T19:30:05Z</dc:date>
    </item>
  </channel>
</rss>

