如何使组的每一行与SAS中的最后一行相匹配
How to make every row of a group match the final one in SAS
我是 SAS 的新手,我希望在最后一列中显示每个组的总数。
我试过这个:
data appledata;
set apples;
by GroupID;
Total_Apples=max(Total_Apples);
run;
不幸的是,当我尝试这个时没有任何变化。我是否缺少某种语法?
请在下面找到我所拥有的代表。
GroupID Number_of_Apples Total_Apples
1 . 0
1 5 5
1 . 5
1 8 13
2 2 2
3 4 4
3 1 5
3 1 6
4 2 2
4 . 2
5 . 0
5 0 0
我希望它看起来像这样:
GroupID Number_of_Apples Total_Apples
1 . 13
1 5 13
1 . 13
1 8 13
2 2 2
3 4 6
3 1 6
3 1 6
4 2 2
4 . 2
5 . 0
5 0 0
任何帮助,参考培训或其他,我们将不胜感激。
你可以做到这一点。如果您打算使用此技术,则需要学习使用 IORC 自动变量。我这里不需要那个。
data apples;
input GroupID Y;
cards;
1 . 0
1 5 5
3 1 5
3 1 6
4 2 2
4 . 2
5 . 0
5 0 0
1 . 5
1 8 13
2 2 2
3 4 4
;;;;
proc print;
run;
proc summary data=apples nway missing;
class groupid;
var y;
output out=summary(index=(groupid)) n=n mean=mean max=max min=min;
run;
data apples2;
set apples;
set summary key=groupid/unique;
run;
proc print;
run;
我是 SAS 的新手,我希望在最后一列中显示每个组的总数。
我试过这个:
data appledata;
set apples;
by GroupID;
Total_Apples=max(Total_Apples);
run;
不幸的是,当我尝试这个时没有任何变化。我是否缺少某种语法?
请在下面找到我所拥有的代表。
GroupID Number_of_Apples Total_Apples
1 . 0
1 5 5
1 . 5
1 8 13
2 2 2
3 4 4
3 1 5
3 1 6
4 2 2
4 . 2
5 . 0
5 0 0
我希望它看起来像这样:
GroupID Number_of_Apples Total_Apples
1 . 13
1 5 13
1 . 13
1 8 13
2 2 2
3 4 6
3 1 6
3 1 6
4 2 2
4 . 2
5 . 0
5 0 0
任何帮助,参考培训或其他,我们将不胜感激。
你可以做到这一点。如果您打算使用此技术,则需要学习使用 IORC 自动变量。我这里不需要那个。
data apples;
input GroupID Y;
cards;
1 . 0
1 5 5
3 1 5
3 1 6
4 2 2
4 . 2
5 . 0
5 0 0
1 . 5
1 8 13
2 2 2
3 4 4
;;;;
proc print;
run;
proc summary data=apples nway missing;
class groupid;
var y;
output out=summary(index=(groupid)) n=n mean=mean max=max min=min;
run;
data apples2;
set apples;
set summary key=groupid/unique;
run;
proc print;
run;