如何使用SAS中的proc函数提取整行max和min?

How to extract entire row of max and min using proc function in SAS?

提问人:Robyn O'Halloran 提问时间:9/19/2023 最后编辑:Robyn O'Halloran 更新时间:9/19/2023 访问量:21

问:

我必须使用 SAS 程序函数确定哪款运动鞋(变量 1)与最高和最低销售额(变量 2)匹配(同一行)。

当前代码:

PROC MEANS DATA = M4.sneaker min max; Class salesThisPeriod; RUN;

变量 SAS 最大 最小 观测值

评论

0赞 Tom 9/19/2023
为什么?这是什么奇怪的家庭作业问题吗?

答:

0赞 Tom 9/19/2023 #1

您可以尝试使用 PROC MEANS(又名 PROC SUMMARY)的 OUTPUT 语句的 IDGROUP 功能。但是要同时获得最小值和最大值,您需要编写两个输出数据集。

proc summary data=sashelp.class ;
  class sex;
  output out=min idgroup(min(age) out[1] (name age height weight)= );
  output out=max idgroup(max(age) out[1] (name age height weight)= );
run;

data both;
  length stat indsname $32 ;
  set min max indsname=indsname;
  by _type_ sex;
  stat=scan(indsname,-1,'.');
run;

结果

Obs    stat    Sex    _TYPE_    _FREQ_     Name     Age    Height    Weight

 1     MIN               0        19      Joyce      11     51.3       50.5
 2     MAX               0        19      Philip     16     72.0      150.0
 3     MIN      F        1         9      Joyce      11     51.3       50.5
 4     MAX      F        1         9      Janet      15     62.5      112.5
 5     MIN      M        1        10      Thomas     11     57.5       85.0
 6     MAX      M        1        10      Philip     16     72.0      150.0