<?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 How to make a variable that creates the average in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-variable-that-creates-the-average/m-p/642616#M191733</link>
    <description>&lt;P&gt;Hi I have a goal variable (numeric): there are multiple goals per person.&lt;/P&gt;
&lt;P&gt;I have a study_id (character) variable that determines the participant.&lt;/P&gt;
&lt;P&gt;I want to create a variable that says what the average goal is for each participant.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 24 Apr 2020 14:44:39 GMT</pubDate>
    <dc:creator>mariamon0</dc:creator>
    <dc:date>2020-04-24T14:44:39Z</dc:date>
    <item>
      <title>How to make a variable that creates the average</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-variable-that-creates-the-average/m-p/642616#M191733</link>
      <description>&lt;P&gt;Hi I have a goal variable (numeric): there are multiple goals per person.&lt;/P&gt;
&lt;P&gt;I have a study_id (character) variable that determines the participant.&lt;/P&gt;
&lt;P&gt;I want to create a variable that says what the average goal is for each participant.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 14:44:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-variable-that-creates-the-average/m-p/642616#M191733</guid>
      <dc:creator>mariamon0</dc:creator>
      <dc:date>2020-04-24T14:44:39Z</dc:date>
    </item>
    <item>
      <title>Creating a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-variable-that-creates-the-average/m-p/642620#M191740</link>
      <description>&lt;P&gt;Hi I have a goal variable (numeric): there are multiple goals per person.&lt;/P&gt;
&lt;P&gt;I have a study_id (character) variable that determines the participant.&lt;/P&gt;
&lt;P&gt;I want to create a variable that says what the average goal is for each participant.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 14:52:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-variable-that-creates-the-average/m-p/642620#M191740</guid>
      <dc:creator>mariamon0</dc:creator>
      <dc:date>2020-04-24T14:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a variable that creates the average</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-variable-that-creates-the-average/m-p/642621#M191735</link>
      <description>&lt;P&gt;Provide an example of what the data set should look like in the result. Is this supposed to be based on some existing data? Goal, from the body of your question, is usually quite a bit different from "average" in your topic title. One is set by outside rule(s) of some sort, the other is calculated from multiple measurements.&lt;/P&gt;
&lt;P&gt;How do we know what the goal value should be?&lt;/P&gt;
&lt;P&gt;What kind of units are involved, if any?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basic might be a data step:&lt;/P&gt;
&lt;PRE&gt;data want;
  input subject $ goal;
datalines;
abc   123.4
pdq   333
sally 41
;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 14:54:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-variable-that-creates-the-average/m-p/642621#M191735</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-24T14:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-variable-that-creates-the-average/m-p/642626#M191741</link>
      <description>&lt;P&gt;Please do not double-post.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 14:55:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-variable-that-creates-the-average/m-p/642626#M191741</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-24T14:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a variable that creates the average</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-variable-that-creates-the-average/m-p/642628#M191743</link>
      <description>&lt;P&gt;A Participants goals could be 1000 one week 2000 the next, 3000 the next week.&lt;/P&gt;
&lt;P&gt;I want to create a variable that is the "average goal" for each participant. So for this participant it would be 2000.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 14:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-variable-that-creates-the-average/m-p/642628#M191743</guid>
      <dc:creator>mariamon0</dc:creator>
      <dc:date>2020-04-24T14:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a variable that creates the average</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-variable-that-creates-the-average/m-p/642630#M191745</link>
      <description>&lt;P&gt;Use PROC MEANS/SUMMARY/UNIVARIATE/SQL.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MEANS is the easiest usually. Notice the use of the BY statement, consider ID to be your participant ID and feature1 to be goals scored, feature2 is yellow cards, feature3 is red cards. You can run the code below and check the different output data sets WANT and WANT2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Create summary statistics for a dataset by a 'grouping' variable and store it in a dataset;

*Generate sample fake data;
data have;
	input ID          feature1         feature2         feature3;
	cards;
1               7.72               5.43              4.35
1               5.54               2.25              8.22 
1               4.43               6.75              2.22
1               3.22               3.21              7.31
2               6.72               2.86              6.11
2               5.89               4.25              5.25 
2               3.43               7.30              8.21
2               1.22               3.55              6.55

;
run;

*Create summary data;
proc means data=have noprint;
	by id;
	var feature1-feature3;
	output out=want median= var= mean= /autoname;
run;

*Show for display;
proc print data=want;
run;

*First done here:https://communities.sas.com/t5/General-SAS-Programming/Getting-creating-new-summary-variables-longitudinal-data/m-p/347940/highlight/false#M44842;
*Another way to present data is as follows;

proc means data=have stackods nway n min max mean median std p5 p95;
    by id;
    var feature1-feature3;
    ods output summary=want2;
run;

*Show for display;
proc print data=want2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264213"&gt;@mariamon0&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi I have a goal variable (numeric): there are multiple goals per person.&lt;/P&gt;
&lt;P&gt;I have a study_id (character) variable that determines the participant.&lt;/P&gt;
&lt;P&gt;I want to create a variable that says what the average goal is for each participant.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 15:08:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-variable-that-creates-the-average/m-p/642630#M191745</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-04-24T15:08:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a variable that creates the average</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-variable-that-creates-the-average/m-p/642631#M191746</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264213"&gt;@mariamon0&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;A Participants goals could be 1000 one week 2000 the next, 3000 the next week.&lt;/P&gt;
&lt;P&gt;I want to create a variable that is the "average goal" for each participant. So for this participant it would be 2000.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;We'd like a SAS data set, as shown by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;in DATA step code, that represents your data.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 15:08:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-variable-that-creates-the-average/m-p/642631#M191746</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-24T15:08:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a variable that creates the average</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-variable-that-creates-the-average/m-p/642640#M191753</link>
      <description>&lt;P&gt;Is there a way to create a new variable name for the average goal for each participant? I want to be able to plot "meangoal"&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data goaldata;&lt;/P&gt;
&lt;P&gt;set goal;&lt;/P&gt;
&lt;P&gt;meangoal=meangoal by study_id;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc sgplot data=goaldata;&lt;/P&gt;
&lt;P&gt;scatter x=date y=goal;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 15:29:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-variable-that-creates-the-average/m-p/642640#M191753</guid>
      <dc:creator>mariamon0</dc:creator>
      <dc:date>2020-04-24T15:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a variable that creates the average</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-variable-that-creates-the-average/m-p/642644#M191754</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264213"&gt;@mariamon0&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;A Participants goals could be 1000 one week 2000 the next, 3000 the next week.&lt;/P&gt;
&lt;P&gt;I want to create a variable that is the "average goal" for each participant. So for this participant it would be 2000.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are we supposed to guess the target goal values? And "week" wasn't previously mentioned.&lt;/P&gt;
&lt;P&gt;As far as I can tell you do not have any data and are trying to create something from scratch. So you could modify my first code example:&lt;/P&gt;
&lt;PRE&gt;data want;
  input subject $ weeknumber goal;
datalines;
abc 1  123.4
abc 2  120.4
abc 3  118.4
pdq 1  333
pdq 2  343
pdq 3  366
pdq 4  377
pdq 5  388
sally 1 11
;&lt;/PRE&gt;
&lt;P&gt;Otherwise clearly describe the values that you currently have that would allow us to "create a goal" and any rules involved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 16:09:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-variable-that-creates-the-average/m-p/642644#M191754</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-24T16:09:28Z</dc:date>
    </item>
  </channel>
</rss>

