<?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: How to divide all the observations based on a sum of a column in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-divide-all-the-observations-based-on-a-sum-of-a-column/m-p/780553#M31642</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;1. I need to make sure columns 'return' and 'invested' are numeric. When I run the code above, 'return' column ends up being a CHAR column and I don't know why&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Because you told SAS that it was character by using a $ after RETURN in the INPUT statement.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;2. Now I want to create a new column and calculate the share of the total return they each got. In this case, the sum of 'return' =97. This is the result I want.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3. Next I want to find their ROI. Which is (return-investment) / investment * 100. This is the result I am looking for&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table want as select *, return/sum(return) as share_of_return,
        (return-invested)/invested*100 as roi 
    from money;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 16 Nov 2021 20:12:59 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-11-16T20:12:59Z</dc:date>
    <item>
      <title>How to divide all the observations based on a sum of a column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-divide-all-the-observations-based-on-a-sum-of-a-column/m-p/780548#M31641</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello, I'm trying to do simple calculations but I'm new and SAS is not intuitive to me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suppose I have this table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data money;
infile datalines delimiter=",";
input name $ return $ invested;
datalines;
Joe,10,100
Bob,7,50
Mary,80,1000
;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which creates this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;/* name | return | invested */
/* _________________________ */
/* Joe  | 10     | 100 */
/* Bob  | 7      | 50 */
/* Mary | 80     | 50 */&lt;/PRE&gt;&lt;P&gt;1. I need to make sure columns 'return' and 'invested' are numeric. When I run the code above, 'return' column ends up being a CHAR column and I don't know why.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Now I want to create a new column and calculate the share of the total return they each got. In this case, the sum of 'return' =97. This is the result I want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;/* name     | return | invested | share_of_return */
/* ____________________________________________ */
/* Joe      |  10   | 100       | 10.30% */
/* Bob      |   7   | 50        | 7.22% */
/* Mary     | 80    | 50        | 82.47% */&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. Next I want to find their ROI. Which is (return-investment) / investment * 100. This is the result I am looking for&lt;/P&gt;&lt;PRE&gt;/* Find ROI */

/* name | return | invested | share_of_return | ROI */
/* ___________________________________________________ */
/* Joe  | 10     | 100      | 10.30%          | -90% */
/* Bob  | 7      | 50       | 7.22%           | -86% */
/* Mary | 80     | 50       | 82.47%          | 60% */&lt;/PRE&gt;&lt;P&gt;I appreciate your explanations and guidance in advanced. This is for a work project and we just switched over to SAS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Nov 2021 20:03:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-divide-all-the-observations-based-on-a-sum-of-a-column/m-p/780548#M31641</guid>
      <dc:creator>heyyou1</dc:creator>
      <dc:date>2021-11-16T20:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to divide all the observations based on a sum of a column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-divide-all-the-observations-based-on-a-sum-of-a-column/m-p/780553#M31642</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;1. I need to make sure columns 'return' and 'invested' are numeric. When I run the code above, 'return' column ends up being a CHAR column and I don't know why&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Because you told SAS that it was character by using a $ after RETURN in the INPUT statement.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;2. Now I want to create a new column and calculate the share of the total return they each got. In this case, the sum of 'return' =97. This is the result I want.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3. Next I want to find their ROI. Which is (return-investment) / investment * 100. This is the result I am looking for&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table want as select *, return/sum(return) as share_of_return,
        (return-invested)/invested*100 as roi 
    from money;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Nov 2021 20:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-divide-all-the-observations-based-on-a-sum-of-a-column/m-p/780553#M31642</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-16T20:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to divide all the observations based on a sum of a column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-divide-all-the-observations-based-on-a-sum-of-a-column/m-p/780555#M31643</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I do not do * 100 (times 100) as I am using PERCENTw.d format&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data money0;
infile datalines delimiter=",";
input name $ return invested;
datalines;
Joe,10,100
Bob,7,50
Mary,80,1000
;
run;

proc means data=money0 sum nway noprint;
var return;
output out=work.abc_xyz sum= / autoname;
run;

data money1;
 set money0;
 if _N_=1 then set work.abc_xyz(drop=_:);
 share_of_return = return / return_sum;
 ROI = (return-invested) / invested;
 format share_of_return ROI percent7.2;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Koen&lt;/P&gt;</description>
      <pubDate>Tue, 16 Nov 2021 20:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-divide-all-the-observations-based-on-a-sum-of-a-column/m-p/780555#M31643</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-11-16T20:18:57Z</dc:date>
    </item>
  </channel>
</rss>

