楼主: aicnzheng
2135 6

[有偿编程] 请教排他性if then 语句的使用 [推广有奖]

  • 0关注
  • 0粉丝

本科生

7%

还不是VIP/贵宾

-

威望
0
论坛币
430 个
通用积分
1.6405
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
545 点
帖子
63
精华
0
在线时间
64 小时
注册时间
2015-11-16
最后登录
2023-7-22

5论坛币
大家好,现有如下数据。
ID Disease_class
1  正常
2  浅表
3  萎缩性胃炎伴浅表性溃疡(说明,归类为萎缩性胃炎)
4  萎缩性胃炎
5  萎缩性胃炎,癌症(归类为癌症)

请问,现在想将以上分类归类,将带有癌症字样的,归为“癌症”,带有萎缩字样但没有癌症的归为“萎缩”,只带有浅表字样的归为浅表,请问如何用if then语句实现呢?
谢谢!!!

关键词:萎缩性胃炎 萎缩性 排他性 浅表性
沙发
superguy333 发表于 2018-8-27 10:54:22 |只看作者 |坛友微信交流群
  1. if Disease_class like ‘%癌症%’ then type=‘癌症’ ;
  2. else if Disease_class like ‘%’萎缩%’ then type=‘萎缩’;
  3. else if Disease_class =‘浅表’ then type =‘浅表’;
  4. else if Disease_class=‘正常’  then type =‘正常’;
复制代码

使用道具

藤椅
小明12345 发表于 2018-8-27 13:23:10 |只看作者 |坛友微信交流群
data testdeomo1;
retain id Disease_class  ;
set testdemo;
if kindex(Disease_class,'癌症') thern y='癌症';
if kindex(Disease_class,'萎缩') thern y='萎缩';
if kindex(Disease_class,'浅表') thern y='浅表';
if kindex(Disease_class,'正常') thern y='正常';
run;
已有 1 人评分论坛币 收起 理由
admin_kefu + 30 热心帮助其他会员

总评分: 论坛币 + 30   查看全部评分

使用道具

板凳
小明12345 发表于 2018-8-27 13:23:58 |只看作者 |坛友微信交流群
data testdeomo1;
retain id Disease_class  ;
set testdemo;
if kindex(Disease_class,'癌症') then y='癌症';
if kindex(Disease_class,'萎缩') then y='萎缩';
if kindex(Disease_class,'浅表') then y='浅表';
if kindex(Disease_class,'正常') then y='正常';
run;

使用道具

报纸
aicnzheng 发表于 2018-8-31 18:46:51 |只看作者 |坛友微信交流群
superguy333 发表于 2018-8-27 10:54
这个不对啊。。

使用道具

地板
aicnzheng 发表于 2018-8-31 18:47:41 |只看作者 |坛友微信交流群
小明12345 发表于 2018-8-27 13:23
data testdeomo1;
retain id Disease_class  ;
set testdemo;
非常感谢,但是看了个帖子,说kindex筛选中文,因为ASCII码的原因会出错

使用道具

7
aicnzheng 发表于 2018-8-31 18:48:35 |只看作者 |坛友微信交流群
自己查了查,如下程序可以!!!
proc sql;
        create table tentative2  as
        select id, class,
                case when class contains '癌症' then  '癌症'
                                     when class contains '肠化' then  '肠化'
                                         when class contains '萎缩' then  '萎缩'
                                         when class contains '浅表' then  '浅表'
                                         else '正常'
                                         end as classnew
                                from tentative ;
                        quit;
proc print data = tentative2;
run;

使用道具

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

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

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

GMT+8, 2024-4-26 14:28