楼主: 尘小烬
2480 3

[问答] 满足多个条件,然后定义一个新的变量,怎么写???例子里面能简化吗? [推广有奖]

  • 0关注
  • 0粉丝

学前班

50%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
33 点
帖子
2
精华
0
在线时间
0 小时
注册时间
2016-3-29
最后登录
2016-5-12

楼主
尘小烬 发表于 2016-3-29 21:59:55 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
  这是我自己写的一个,刚开始学,不知道怎么去简化,sex=1是共同的条件,怎么简提出来                                                                                                                                                                                                                          if                                                                                                                                                                                                                                                              
sex=1 and age=7 and height<=111.3or                                                                                                                                                                                                                             
sex=1 and  age=8 and height<=115.4or                                                                                                                                                                                                                           
sex=1 and  age=9 and height<=120.6or                                                                                                                                                                                                                           
sex=1 and  age=10 and height<=125.2or                                                                                                                                                                                                                           
sex=1 and  age=11 and height<=129.1 or                                                                                                                                                                                                                          
sex=1 and  age=12 and height<=133.1 or                                                                                                                                                                                                                          
sex=1 and  age=13 and height<=136.9 or                                                                                                                                                                                                                          
sex=1 and  age=14 and height<=141.9 or                                                                                                                                                                                                                          
sex=1 and  age=15 and height<=149.6 or                                                                                                                                                                                                                          
sex=1 and  age=16 and height<=155.1 or                                                                                                                                                                                                                          
sex=1 and  age=17 and height<=156.8 or                                                                                                                                                                                                                          
sex=1 and  age=18 and height<=157.4 or                                                                                                                                                                                                                          
sex=1 and  age=19 and height<=158.1                                                                                                                                                                                                                             
then  yybl=1;                                                                                                                                                                                                                                                                                                                                                                                                                                                
      


二维码

扫码加我 拉你入群

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

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

关键词:Eight SEX 不知道 Age

沙发
yingzi2003 发表于 2016-3-30 03:20:22
好像也没有特别简化:
   if sex=1 and ( (age=7 and height<=111.3) or     
                (age=8 and height<=115.4) or     
                (age=9 and height<=120.6) or     
                (age=10 and height<=125.2) or   
                (age=11 and height<=129.1) or   
                (age=12 and height<=133.1) or   
                (age=13 and height<=136.9) or   
                (age=14 and height<=141.9) or   
                (age=15 and height<=149.6) or   
                (age=16 and height<=155.1) or   
                (age=17 and height<=156.8) or   
                (age=18 and height<=157.4) or   
                (age=19 and height<=158.1) )  then  yybl=1;   


或者用MACRO:

%let value_lst=111.3 115.4 120.6 125.2 129.1 133.1 136.9 141.9 149.6 155.1 156.8 157.4 158.1 ;
%MACRO getdata ;
  if sex = 1 and (
     %do i=7 %to 19 ;
        %let values=%scan(&value_lst, %eval(&i-6), ' ') ;
          ( age=&i and height <= &values )
            %if &i < 19 %then or ;
     %end ;
                 ) then  yybl=1;
%MEND getdata ;

data newdata ;
   set olddata ;
   %getdata
run;
已有 1 人评分论坛币 热心指数 收起 理由
admin_kefu + 40 + 2 热心帮助其他会员

总评分: 论坛币 + 40  热心指数 + 2   查看全部评分

藤椅
jerryfun007 发表于 2016-3-30 10:09:17
yybl=(sex=1 and ((age=7 and height<=111.3) or     
                 (age=8 and height<=115.4) or     
                 (age=9 and height<=120.6) or     
                 (age=10 and height<=125.2) or   
                (age=11 and height<=129.1) or   
                 (age=12 and height<=133.1) or   
                 (age=13 and height<=136.9) or   
                 (age=14 and height<=141.9) or   
                 (age=15 and height<=149.6) or   
                 (age=16 and height<=155.1) or   
                 (age=17 and height<=156.8) or   
                 (age=18 and height<=157.4) or   
                 (age=19 and height<=158.1) ))

板凳
尘小烬 发表于 2016-3-30 10:15:54
yingzi2003 发表于 2016-3-30 03:20
好像也没有特别简化:
   if sex=1 and ( (age=7 and height
谢谢

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-2-1 05:31