<?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 Creating new numeric variable based on values of other variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-new-numeric-variable-based-on-values-of-other-variables/m-p/796372#M255542</link>
    <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a new numeric variable for each participant which is the sum of all &lt;STRONG&gt;menge&lt;/STRONG&gt; values from this participant. Each participant has it's own unique Id which is the variable &lt;STRONG&gt;TN_NR&lt;/STRONG&gt; and several values for &lt;STRONG&gt;menge&lt;/STRONG&gt;. That's why there are several rows for one participant. Here is a part of my dataset:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="QA.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/68495i8C5AE28C14FF4C67/image-size/medium?v=v2&amp;amp;px=400" role="button" title="QA.png" alt="QA.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I came this far with the SAS code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data epic;
set epic;
newmenge = sum (menge);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am new to programming in SAS and I don't know how to tell SAS to summarize all values of &lt;STRONG&gt;menge&lt;/STRONG&gt; for each participant into the new variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate every help!! Thanks in advance!!&lt;/P&gt;</description>
    <pubDate>Tue, 15 Feb 2022 18:48:20 GMT</pubDate>
    <dc:creator>AgaWS</dc:creator>
    <dc:date>2022-02-15T18:48:20Z</dc:date>
    <item>
      <title>Creating new numeric variable based on values of other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-new-numeric-variable-based-on-values-of-other-variables/m-p/796372#M255542</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a new numeric variable for each participant which is the sum of all &lt;STRONG&gt;menge&lt;/STRONG&gt; values from this participant. Each participant has it's own unique Id which is the variable &lt;STRONG&gt;TN_NR&lt;/STRONG&gt; and several values for &lt;STRONG&gt;menge&lt;/STRONG&gt;. That's why there are several rows for one participant. Here is a part of my dataset:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="QA.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/68495i8C5AE28C14FF4C67/image-size/medium?v=v2&amp;amp;px=400" role="button" title="QA.png" alt="QA.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I came this far with the SAS code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data epic;
set epic;
newmenge = sum (menge);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am new to programming in SAS and I don't know how to tell SAS to summarize all values of &lt;STRONG&gt;menge&lt;/STRONG&gt; for each participant into the new variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate every help!! Thanks in advance!!&lt;/P&gt;</description>
      <pubDate>Tue, 15 Feb 2022 18:48:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-new-numeric-variable-based-on-values-of-other-variables/m-p/796372#M255542</guid>
      <dc:creator>AgaWS</dc:creator>
      <dc:date>2022-02-15T18:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new numeric variable based on values of other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-new-numeric-variable-based-on-values-of-other-variables/m-p/796376#M255544</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;******************************************************;
*Add average value to a dataset;
*Solution 1 - PROC MEANS + Data step;
******************************************************;

proc means data=sashelp.class noprint;
    output out=avg_values mean(height)=avg_height;
run;

data class_data;
    set sashelp.class;

    if _n_=1 then
        set avg_values;
run;

proc print data=class;
run;

*Solution 2 - PROC SQL - note the warning in the log;
PROC SQL;
Create table class_sql as
select *, mean(height) as avg_height
from sashelp.class;
quit;

******************************************************;
*Add average value to a dataset - with grouping variables;
*Solution 1 - PROC MEANS + Data step;
******************************************************;
proc means data=sashelp.class noprint nway;
class sex;
    output out=avg_values mean(height)=avg_height;
run;

*sort data before merge;
proc sort data=sashelp.class out=class;
by sex;
run;

data class_data;
 merge class avg_values;
 by sex;


run;

proc print data=class_data;
run;

*Solution 2 - PROC SQL - note the warning in the log;
PROC SQL;
Create table class_sql as
select *, mean(height) as avg_height
from sashelp.class
group by sex;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381178"&gt;@AgaWS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi guys,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a new numeric variable for each participant which is the sum of all &lt;STRONG&gt;menge&lt;/STRONG&gt; values from this participant. Each participant has it's own unique Id which is the variable &lt;STRONG&gt;TN_NR&lt;/STRONG&gt; and several values for &lt;STRONG&gt;menge&lt;/STRONG&gt;. That's why there are several rows for one participant. Here is a part of my dataset:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="QA.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/68495i8C5AE28C14FF4C67/image-size/medium?v=v2&amp;amp;px=400" role="button" title="QA.png" alt="QA.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I came this far with the SAS code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data epic;
set epic;
newmenge = sum (menge);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am new to programming in SAS and I don't know how to tell SAS to summarize all values of &lt;STRONG&gt;menge&lt;/STRONG&gt; for each participant into the new variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I appreciate every help!! Thanks in advance!!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Feb 2022 18:53:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-new-numeric-variable-based-on-values-of-other-variables/m-p/796376#M255544</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-02-15T18:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new numeric variable based on values of other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-new-numeric-variable-based-on-values-of-other-variables/m-p/796377#M255545</link>
      <description>&lt;P&gt;Try PROC SUMMARY&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=epic nway;
    class tn_nr;
    var menge;
    output out=want sum=newmenge;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want this sum inserted back into your original data set&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
    merge epic want(drop= _freq_ _type_);
    by tn_nr;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Feb 2022 19:10:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-new-numeric-variable-based-on-values-of-other-variables/m-p/796377#M255545</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-02-15T19:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new numeric variable based on values of other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-new-numeric-variable-based-on-values-of-other-variables/m-p/796378#M255546</link>
      <description>Replace mean with SUM in your use case.</description>
      <pubDate>Tue, 15 Feb 2022 18:54:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-new-numeric-variable-based-on-values-of-other-variables/m-p/796378#M255546</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-02-15T18:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new numeric variable based on values of other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-new-numeric-variable-based-on-values-of-other-variables/m-p/796379#M255547</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381178"&gt;@AgaWS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I came this far with the SAS code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data epic;
set epic;
newmenge = sum (menge);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am new to programming in SAS and I don't know how to tell SAS to summarize all values of &lt;STRONG&gt;menge&lt;/STRONG&gt; for each participant into the new variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I appreciate every help!! Thanks in advance!!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hopefully, this advice will help you. The SUM() function in a DATA step, and nearly all functions in a DATA step, work by performing the function across a row of values. If you wanted to sum many variables in a row, the SUM function is what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you want the sum to go down a column, not across a row. That's where you need to use PROCs, which (with a few rare exceptions), perform arithmetic down column(s).&lt;/P&gt;</description>
      <pubDate>Tue, 15 Feb 2022 19:18:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-new-numeric-variable-based-on-values-of-other-variables/m-p/796379#M255547</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-02-15T19:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new numeric variable based on values of other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-new-numeric-variable-based-on-values-of-other-variables/m-p/796485#M255592</link>
      <description>&lt;P&gt;Thank you so much for the help!! I could manage it perfectly with your advice.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Feb 2022 08:56:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-new-numeric-variable-based-on-values-of-other-variables/m-p/796485#M255592</guid>
      <dc:creator>AgaWS</dc:creator>
      <dc:date>2022-02-16T08:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new numeric variable based on values of other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-new-numeric-variable-based-on-values-of-other-variables/m-p/796486#M255593</link>
      <description>&lt;P&gt;Thank you so much for the support!!&lt;/P&gt;</description>
      <pubDate>Wed, 16 Feb 2022 08:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-new-numeric-variable-based-on-values-of-other-variables/m-p/796486#M255593</guid>
      <dc:creator>AgaWS</dc:creator>
      <dc:date>2022-02-16T08:57:01Z</dc:date>
    </item>
  </channel>
</rss>

