<?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: Creating a new variable that shows percentage of total observations in a group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-that-shows-percentage-of-total/m-p/217254#M40012</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I like &lt;STRONG style="font-size: 12px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;A _jive_internal="true" class="jiveTT-hover-user jive-username-link" data-avatarid="2333" data-externalid="" data-presence="null" data-userid="260198" data-username="ballardw" href="https://communities.sas.com/people/ballardw" id="jive-26019847507736649283186" style="padding: 0 3px 0 0; font-weight: inherit; font-style: inherit; font-size: 1.1em; font-family: inherit; color: #0e66ba;"&gt;ballardw&lt;/A&gt;&lt;/STRONG&gt; 's code. Question is what form of data you would like ? report or table ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;

data have;
infile cards dsd dlm=',';
length group subgroup $15.;
input group $ subgroup $ num_obs;
cards;
Admin,Receptionists,5
Admin,Assistants,4
Admin,Managers,3
CompSci,DataAnalysts,10
CompSci,ITSupport,4
;
run;
proc tabulate data=have;
class group subgroup;
var num_obs;
table group*subgroup, num_obs*(sum pctsum);
run;
&lt;/PRE&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;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 20 May 2015 13:34:28 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2015-05-20T13:34:28Z</dc:date>
    <item>
      <title>Creating a new variable that shows percentage of total observations in a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-that-shows-percentage-of-total/m-p/217248#M40006</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all! I have just started a new job and have been teaching myself to use SAS. Progress is slow since I have very little experience with programming languages. I would be incredibly appreciative of any help with this problem!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a large raw macro data set. Based on this raw data, a former co-worker used SAS to make an Excel spreadsheet. In the spreadsheet, there are 3 columns: Group, Subgroup, and the Number of Observations of Subgroup (i.e. the number of times the subgroup was observed in the data). Specifically, the Groups are things like “Administrative Services”, and the Subgroups include specific jobs like “Receptionists”, “Assistants”, and “Managers”. Below I have made an example of what the table looks like. In reality, there aren’t just 2 Groups, there are hundreds!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have imported the Excel data into SAS. My question is: &lt;STRONG&gt;How can I make the “Share of Group” column in SAS?&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE border="1" cellpadding="0" cellspacing="0" height="999" style="padding: 0px 5.4pt; border: currentColor; width: 434px; height: 779px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD style="padding: 0px 5.4pt; border: 1pt solid windowtext;" valign="top" width="170"&gt;&lt;BR /&gt; &lt;P align="center" style="text-align: center;"&gt;Group&lt;/P&gt;&lt;BR /&gt; &lt;/TD&gt;&lt;TD style="border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: windowtext windowtext windowtext currentColor; padding: 0px 5.4pt;" valign="top" width="167"&gt;&lt;BR /&gt; &lt;P align="center" style="text-align: center;"&gt;Subgroup&lt;/P&gt;&lt;BR /&gt; &lt;/TD&gt;&lt;TD style="border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: windowtext windowtext windowtext currentColor; padding: 0px 5.4pt;" valign="top" width="166"&gt;&lt;BR /&gt; &lt;P align="center" style="text-align: center;"&gt;Number of Observations&lt;/P&gt;&lt;BR /&gt; &lt;/TD&gt;&lt;TD style="border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: windowtext windowtext windowtext currentColor; padding: 0px 5.4pt;" valign="top" width="136"&gt;&lt;BR /&gt; &lt;P align="center" style="text-align: center;"&gt;Share of Group&lt;/P&gt;&lt;BR /&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD rowspan="3" style="border-width: medium 1pt 1pt; border-style: none solid solid; border-color: currentColor windowtext windowtext; padding: 0px 5.4pt;" valign="top" width="170"&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;P&gt;Administrative Services&lt;/P&gt;&lt;BR /&gt; &lt;/TD&gt;&lt;TD style="border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: currentColor windowtext windowtext currentColor; padding: 0px 5.4pt;" valign="top" width="167"&gt;&lt;BR /&gt; &lt;P&gt;Receptionists&lt;/P&gt;&lt;BR /&gt; &lt;/TD&gt;&lt;TD style="border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: currentColor windowtext windowtext currentColor; padding: 0px 5.4pt;" valign="top" width="166"&gt;&lt;BR /&gt; &lt;P align="center" style="text-align: center;"&gt;5&lt;/P&gt;&lt;BR /&gt; &lt;/TD&gt;&lt;TD style="border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: currentColor windowtext windowtext currentColor; padding: 0px 5.4pt;" valign="top" width="136"&gt;&lt;BR /&gt; &lt;P&gt;41.6%&lt;/P&gt;&lt;BR /&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: currentColor windowtext windowtext currentColor; padding: 0px 5.4pt;" valign="top" width="167"&gt;&lt;BR /&gt; &lt;P&gt;Assistants&lt;/P&gt;&lt;BR /&gt; &lt;/TD&gt;&lt;TD style="border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: currentColor windowtext windowtext currentColor; padding: 0px 5.4pt;" valign="top" width="166"&gt;&lt;BR /&gt; &lt;P align="center" style="text-align: center;"&gt;4&lt;/P&gt;&lt;BR /&gt; &lt;/TD&gt;&lt;TD style="border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: currentColor windowtext windowtext currentColor; padding: 0px 5.4pt;" valign="top" width="136"&gt;&lt;BR /&gt; &lt;P&gt;33.3%&lt;/P&gt;&lt;BR /&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: currentColor windowtext windowtext currentColor; padding: 0px 5.4pt;" valign="top" width="167"&gt;&lt;BR /&gt; &lt;P&gt;Managers&lt;/P&gt;&lt;BR /&gt; &lt;/TD&gt;&lt;TD style="border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: currentColor windowtext windowtext currentColor; padding: 0px 5.4pt;" valign="top" width="166"&gt;&lt;BR /&gt; &lt;P align="center" style="text-align: center;"&gt;3&lt;/P&gt;&lt;BR /&gt; &lt;/TD&gt;&lt;TD style="border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: currentColor windowtext windowtext currentColor; padding: 0px 5.4pt;" valign="top" width="136"&gt;&lt;BR /&gt; 25%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD rowspan="2" style="border-width: medium 1pt 1pt; border-style: none solid solid; border-color: currentColor windowtext windowtext; padding: 0px 5.4pt;" valign="top" width="170"&gt;&lt;BR /&gt; &lt;P&gt;Computer Science&lt;/P&gt;&lt;BR /&gt; &lt;/TD&gt;&lt;TD style="border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: currentColor windowtext windowtext currentColor; padding: 0px 5.4pt;" valign="top" width="167"&gt;&lt;BR /&gt; &lt;P&gt;Data Analysts&lt;/P&gt;&lt;BR /&gt; &lt;/TD&gt;&lt;TD style="border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: currentColor windowtext windowtext currentColor; padding: 0px 5.4pt;" valign="top" width="166"&gt;&lt;BR /&gt; &lt;P align="center" style="text-align: center;"&gt;10&lt;/P&gt;&lt;BR /&gt; &lt;/TD&gt;&lt;TD style="border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: currentColor windowtext windowtext currentColor; padding: 0px 5.4pt;" valign="top" width="136"&gt;&lt;BR /&gt; &lt;P&gt;71.4%&lt;/P&gt;&lt;BR /&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: currentColor windowtext windowtext currentColor; padding: 0px 5.4pt;" valign="top" width="167"&gt;&lt;BR /&gt; &lt;P&gt;IT Support&lt;/P&gt;&lt;BR /&gt; &lt;/TD&gt;&lt;TD style="border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: currentColor windowtext windowtext currentColor; padding: 0px 5.4pt;" valign="top" width="166"&gt;&lt;BR /&gt; &lt;P align="center" style="text-align: center;"&gt;4&lt;/P&gt;&lt;BR /&gt; &lt;/TD&gt;&lt;TD style="border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: currentColor windowtext windowtext currentColor; padding: 0px 5.4pt;" valign="top" width="136"&gt;&lt;BR /&gt;&amp;nbsp; 28.5%&lt;BR /&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I would like to do is the following: For each Subgroup, calculate its percentage share of the entire group based on the Number of Observations. For example, I would like to be able to calculate a new variable that will show that Receptionists were 41.6% of all observed Administrative Services employees, Assistants were 33.3%, etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since I have a large number of Groups, I am guessing that the best way to do this for each Group is to make a macro, but I’m not sure what to tell SAS to do in the macro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you so much for reading this! I really appreciate any help or tips I can get.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 May 2015 16:16:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-that-shows-percentage-of-total/m-p/217248#M40006</guid>
      <dc:creator>grande44</dc:creator>
      <dc:date>2015-05-19T16:16:45Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable that shows percentage of total observations in a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-that-shows-percentage-of-total/m-p/217249#M40007</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PROC FREQ, with BY GROUP; with the OUT= option will give you this information&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 May 2015 16:24:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-that-shows-percentage-of-total/m-p/217249#M40007</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-05-19T16:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable that shows percentage of total observations in a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-that-shows-percentage-of-total/m-p/217250#M40008</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;proc tabulate data=have;&lt;/P&gt;&lt;P&gt;class group subgroup;&lt;/P&gt;&lt;P&gt;table group*subgroup, n pctn&amp;lt;subgroup&amp;gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Will make a summary table directly similar to what you want.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 May 2015 16:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-that-shows-percentage-of-total/m-p/217250#M40008</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-05-19T16:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable that shows percentage of total observations in a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-that-shows-percentage-of-total/m-p/217251#M40009</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks so much for your reply! Unfortunately this didn't work. SAS counted how many times the name of the Subgroup appeared in the Group, and did not use the Number of Observations variable instead. So my table ended up looking like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Receptionists 1 0.33&lt;/P&gt;&lt;P&gt;Assistants 1 0.33&lt;/P&gt;&lt;P&gt;Managers 1 0.33 &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 May 2015 16:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-that-shows-percentage-of-total/m-p/217251#M40009</guid>
      <dc:creator>grande44</dc:creator>
      <dc:date>2015-05-19T16:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable that shows percentage of total observations in a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-that-shows-percentage-of-total/m-p/217252#M40010</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think this is what you are looking for.&amp;nbsp; Two sql queries will get the job done.&amp;nbsp; Run this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;infile cards dsd dlm=',';&lt;/P&gt;&lt;P&gt;length group subgroup $15.;&lt;/P&gt;&lt;P&gt;input group $ subgroup $ num_obs;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;Admin,Receptionists,5&lt;/P&gt;&lt;P&gt;Admin,Assistants,4&lt;/P&gt;&lt;P&gt;Admin,Managers,3&lt;/P&gt;&lt;P&gt;CompSci,DataAnalysts,10&lt;/P&gt;&lt;P&gt;CompSci,ITSupport,4&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;proc sql;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select group,subgroup,num_obs/tot_obs as share format=percent7.1&lt;/P&gt;&lt;P&gt;from(select *,sum(num_obs) as tot_obs&lt;/P&gt;&lt;P&gt;from have&lt;/P&gt;&lt;P&gt;group by group);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 May 2015 16:58:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-that-shows-percentage-of-total/m-p/217252#M40010</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-05-19T16:58:18Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable that shows percentage of total observations in a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-that-shows-percentage-of-total/m-p/217253#M40011</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much! You, sir, have just made my day so much easier.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 May 2015 17:07:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-that-shows-percentage-of-total/m-p/217253#M40011</guid>
      <dc:creator>grande44</dc:creator>
      <dc:date>2015-05-19T17:07:17Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable that shows percentage of total observations in a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-that-shows-percentage-of-total/m-p/217254#M40012</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I like &lt;STRONG style="font-size: 12px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;A _jive_internal="true" class="jiveTT-hover-user jive-username-link" data-avatarid="2333" data-externalid="" data-presence="null" data-userid="260198" data-username="ballardw" href="https://communities.sas.com/people/ballardw" id="jive-26019847507736649283186" style="padding: 0 3px 0 0; font-weight: inherit; font-style: inherit; font-size: 1.1em; font-family: inherit; color: #0e66ba;"&gt;ballardw&lt;/A&gt;&lt;/STRONG&gt; 's code. Question is what form of data you would like ? report or table ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;

data have;
infile cards dsd dlm=',';
length group subgroup $15.;
input group $ subgroup $ num_obs;
cards;
Admin,Receptionists,5
Admin,Assistants,4
Admin,Managers,3
CompSci,DataAnalysts,10
CompSci,ITSupport,4
;
run;
proc tabulate data=have;
class group subgroup;
var num_obs;
table group*subgroup, num_obs*(sum pctsum);
run;
&lt;/PRE&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;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2015 13:34:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-that-shows-percentage-of-total/m-p/217254#M40012</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-05-20T13:34:28Z</dc:date>
    </item>
  </channel>
</rss>

