BookmarkSubscribeRSS Feed
mariamon0
Fluorite | Level 6

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.

 

8 REPLIES 8
mariamon0
Fluorite | Level 6

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.

 

ballardw
Super User

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
;

 

mariamon0
Fluorite | Level 6

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.

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
ballardw
Super User

@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.

 

 

Reeza
Super User

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.

 


 

mariamon0
Fluorite | Level 6

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;

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 935 views
  • 2 likes
  • 5 in conversation