Good morning, I need help with code to create a variable that is the mean of a series of values from a long data set. For example, the data I have looks like this:
ID | Event | Time (ms) |
1 | A | 1.2 |
1 | B | 3.3 |
1 | A | 1.1 |
1 | B | 2.3 |
1 | A | 0.9 |
1 | B | 1.9 |
1 | A | 1.4 |
2 | A | 2.3 |
2 | B | 3.2 |
2 | A | 1.9 |
2 | B | 2.8 |
2 | A | 1.7 |
2 | B | 3.1 |
And what I need is data that looks like this:
ID | Event | Mean time (ms) |
1 | A | 1.14 |
1 | B | 2.43 |
2 | A | 1.95 |
2 | B | 3.03 |
Do I need to reformat to wide dataset to accomplish this, or is there another way?
Thanks in advance!
PROC MEANS DATA=HAVE MEAN NWAY;
CLASS ID EVENT;
VAR TIME;
output out=work.ContainsMean mean= / autoname;
RUN;
Koen
PROC MEANS DATA=HAVE MEAN NWAY;
CLASS ID EVENT;
VAR TIME;
output out=work.ContainsMean mean= / autoname;
RUN;
Koen
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.