楼主: tj0412ymy
2797 8

[问答] 取出众多变量中大于0的最小值 [推广有奖]

  • 2关注
  • 48粉丝

副教授

65%

还不是VIP/贵宾

-

威望
0
论坛币
11510 个
通用积分
12.6975
学术水平
72 点
热心指数
91 点
信用等级
64 点
经验
29292 点
帖子
545
精华
0
在线时间
1203 小时
注册时间
2009-3-10
最后登录
2024-2-15

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
比如有8个字段:

x1

x2

x3

x4

x5

x6

x7

x8

12

0

3

6

8

0

23

0


想生成一个新的字段y: 新字段的值是x1-x8中大于0的最小值,即y=3

x1

x2

x3

x4

x5

x6

x7

x8

y

12

0

3

6

8

0

23

0

3



请问大侠如何在DATA步中实现?

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:多变量 最小值 data步 Data 如何

对SAS和统计方面感兴趣的朋友,请加SAS学习和认证讨论群:169157207。欢迎在群上讨论!
沙发
pl172231 发表于 2012-5-23 19:11:01 |只看作者 |坛友微信交流群
data kk;
set kk;
m=1000000;
if m>x1 and  x1>0 then m=x1;
if m>x2 and  x2>0 then m=x2;
if m>x3 and  x3>0 then m=x3;
if m>x4 and  x4>0 then m=x4;
if m>x5 and  x5>0 then m=x5;
if m>x6 and  x6>0 then m=x6;
if m>x7 and  x7>0 then m=x7;
if m>x8 and  x8>0 then m=x8;
run;

使用道具

藤椅
bobguy 发表于 2012-5-24 09:31:16 |只看作者 |坛友微信交流群
See example below.

data t1;
array x(*) x1-x8 (0,-1,4,3,5,6,7,8);
y=1e308;
do i=1 to dim (x);
   if 0<x[i]<y then y=x[i];
end;
run;

proc print;run;

使用道具

板凳
sunset1986 发表于 2012-5-24 09:34:13 |只看作者 |坛友微信交流群
data test;
input X1 X2 X3 X4 X5 X6 X7 X8 @@;
cards;
1        0        15        7        3        4        -2        -3
3        5        7        -1        2        -6        0        4
7        4        6        -6        3        5        0        7
15        12        4        -4        -5        0        3        8
1        3        5        7        -5        0        5        7
6        4        8        -7        0        2        5        4
;

data test1 (drop = i Z1-Z8);
        array X[8] X1-X8;
        array Z[8] Z1-Z8;
        set test;
        do i=1 to 8;
                if X[i] gt 0 then Z[i]=X[i];
                        else Z[i]='';
        end;
        Y=min (of Z1-Z8);
run;
An honest tale speeds best being plainly told.
Cheers!

使用道具

报纸
sunset1986 发表于 2012-5-24 09:34:56 |只看作者 |坛友微信交流群
我觉得这样可以实现更多行数据的同时运算,您看看是否符合要求,呵呵~
欢迎交流哈
An honest tale speeds best being plainly told.
Cheers!

使用道具

地板
sunset1986 发表于 2012-5-24 09:57:09 |只看作者 |坛友微信交流群
bobguy 发表于 2012-5-24 09:31
See example below.

data t1;
很显然,您的这个逻辑判别:
do i=1 to dim (x);
   if 0<x<y then y=x;
end;
写得非常巧妙,赞!
An honest tale speeds best being plainly told.
Cheers!

使用道具

7
chendonghui1987 发表于 2012-5-24 10:03:44 |只看作者 |坛友微信交流群
楼上正解

使用道具

8
遇女心惊 发表于 2012-5-24 14:21:03 |只看作者 |坛友微信交流群
  1. data aa;
  2.         input x1-x8 @@;
  3. cards;
  4. 12 0 3 6 8 0 23 0
  5. ;
  6. run;

  7. data aa;
  8.         set aa;

  9.         array vl(*) x1-x8;
  10.         y=.;
  11.         do i=1 to dim(vl);
  12.                 if 0<vl(i) then y=min(y,vl(i));
  13.         end;

  14.         put y=;
  15. run;
复制代码

使用道具

9
yongjiang2 发表于 2012-7-3 11:16:00 |只看作者 |坛友微信交流群
学习

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-22 10:56