Dear friends,
How can I average column values of semi-duplicated rows and replace them with only one row?
In the following table (HAVE) the rows A5, A10, B7 and C6 are duplicated.
time | anomaly |
A1 | 42 |
A2 | 43 |
A3 | 45 |
A4 | 48 |
A5 | 55 |
A5 | 51 |
A6 | 65 |
A7 | 75 |
A8 | 63 |
A9 | 50 |
A10 | 48 |
A10 | 47 |
A10 |
51 |
A10 | 55 |
A11 | 42 |
A12 | 44 |
B1 | 125 |
B2 | 128 |
B3 | 125 |
B4 | 132 |
B5 | 139 |
B6 | 141 |
B7 | 158 |
B7 | 159 |
B7 | 161 |
B7 | 147 |
B7 | 144 |
B8 | 150 |
B9 | 142 |
B10 | 147 |
B11 | 122 |
B12 | 123 |
C1 | 1135 |
C2 | 1139 |
C3 | 1135 |
C4 | 1144 |
C5 | 1147 |
C6 | 1151 |
C6 | 1144 |
C7 | 1159 |
C8 | 1144 |
C9 | 1140 |
C10 | 1138 |
C11 | 1133 |
C12 | 1129 |
I need only one row of each of those duplicated rows like below:
time | anomaly |
A1 | 42 |
A2 | 43 |
A3 | 45 |
A4 | 48 |
A5 | 53 |
A6 | 65 |
A7 | 75 |
A8 | 63 |
A9 | 50 |
A10 | 50.25 |
A11 | 42 |
A12 | 44 |
B1 | 125 |
B2 | 128 |
B3 | 125 |
B4 | 132 |
B5 | 139 |
B6 | 141 |
B7 | 153.8 |
B8 | 150 |
B9 | 142 |
B10 | 147 |
B11 | 122 |
B12 | 123 |
C1 | 1135 |
C2 | 1139 |
C3 | 1135 |
C4 | 1144 |
C5 | 1147 |
C6 | 1147.5 |
C7 | 1159 |
C8 | 1144 |
C9 | 1140 |
C10 | 1138 |
C11 | 1133 |
C12 | 1129 |
proc summary data=have nway;
class time;
var anomaly;
output out=want mean=;
run;
Please provide data as a SAS data step. Do not provide data as screen captures. We have asked for your compliance previously, you would help us, and help yourself, by not providing data as screen captures.
You can use PROC PRINT
In PROC SQL:
data have;
infile datalines;
input time $ anomaly;
datalines;
A1 42
A2 43
A3 45
A4 48
A5 55
A5 51
A6 65
A7 75
A8 63
A9 50
A10 48
A10 47
A10 51
A10 55
A11 42
A12 44
B1 125
B2 128
B3 125
B4 132
B5 139
B6 141
B7 158
B7 159
B7 161
B7 147
B7 144
B8 150
B9 142
B10 147
B11 122
B12 123
C1 1135
C2 1139
C3 1135
C4 1144
C5 1147
C6 1151
C6 1144
C7 1159
C8 1144
C9 1140
C10 1138
C11 1133
C12 1129
;
run;
proc sql;
create table need (drop=ob) as
select distinct(time),mean(anomaly) as anomaly, monotonic() as ob from have
group by time
order by ob;
quit;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.