Hi I have a goal variable (numeric): there are multiple goals per person.
I have a study_id (character) variable that determines the participant.
I want to create a variable that says what the average goal is for each participant.
Hi I have a goal variable (numeric): there are multiple goals per person.
I have a study_id (character) variable that determines the participant.
I want to create a variable that says what the average goal is for each participant.
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.
How do we know what the goal value should be?
What kind of units are involved, if any?
Basic might be a data step:
data want; input subject $ goal; datalines; abc 123.4 pdq 333 sally 41 ;
A Participants goals could be 1000 one week 2000 the next, 3000 the next week.
I want to create a variable that is the "average goal" for each participant. So for this participant it would be 2000.
@mariamon0 wrote:
A Participants goals could be 1000 one week 2000 the next, 3000 the next week.
I want to create a variable that is the "average goal" for each participant. So for this participant it would be 2000.
We'd like a SAS data set, as shown by @ballardw in DATA step code, that represents your data.
@mariamon0 wrote:
A Participants goals could be 1000 one week 2000 the next, 3000 the next week.
I want to create a variable that is the "average goal" for each participant. So for this participant it would be 2000.
Are we supposed to guess the target goal values? And "week" wasn't previously mentioned.
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:
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 ;
Otherwise clearly describe the values that you currently have that would allow us to "create a goal" and any rules involved.
Use PROC MEANS/SUMMARY/UNIVARIATE/SQL.
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.
*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;
@mariamon0 wrote:
Hi I have a goal variable (numeric): there are multiple goals per person.
I have a study_id (character) variable that determines the participant.
I want to create a variable that says what the average goal is for each participant.
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"
data goaldata;
set goal;
meangoal=meangoal by study_id;
run;
proc sgplot data=goaldata;
scatter x=date y=goal;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.