Hello, all, I have a measurement raw data table saving one sample that took 5 measurements,
a simple example is below:
ID col1
001 0.5
001 0.4
001 0.6
001 0.55
001 0.52
I need to take create a new table, and average the col1 as a single value regarding the specific ID, in this case, the above datatable should be:
ID col1
001 average of (0.5+0.4+0.6+0.55+0.55).
Any suggestions on the codes? it is a huge database.
Many thanks
PROC MEANS can be used to summarize data
*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;
@Jonison wrote:
Hello, all, I have a measurement raw data table saving one sample that took 5 measurements,
a simple example is below:
ID col1
001 0.5
001 0.4
001 0.6
001 0.55
001 0.52
I need to take create a new table, and average the col1 as a single value regarding the specific ID, in this case, the above datatable should be:
ID col1
001 average of (0.5+0.4+0.6+0.55+0.55).
Any suggestions on the codes? it is a huge database.
Many thanks
PROC MEANS can be used to summarize data
*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;
@Jonison wrote:
Hello, all, I have a measurement raw data table saving one sample that took 5 measurements,
a simple example is below:
ID col1
001 0.5
001 0.4
001 0.6
001 0.55
001 0.52
I need to take create a new table, and average the col1 as a single value regarding the specific ID, in this case, the above datatable should be:
ID col1
001 average of (0.5+0.4+0.6+0.55+0.55).
Any suggestions on the codes? it is a huge database.
Many thanks
Thank you so much!
You may try proc sql as well
proc sql;
create table want as select id, avg(col1) as col1 from have group by id;
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.