楼主: tanaya
1465 7

挑选变量 [推广有奖]

  • 3关注
  • 1粉丝

硕士生

96%

还不是VIP/贵宾

-

威望
0
论坛币
700 个
通用积分
4.0600
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
14057 点
帖子
73
精华
0
在线时间
314 小时
注册时间
2012-3-20
最后登录
2023-11-9

楼主
tanaya 发表于 2013-8-4 10:40:43 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
各位好!
       用SAS整理数据过程中发现如下问题,请教下大家:[img=0,1]file:///C:/Documents%20and%20Settings/Administrator/Application%20Data/Tencent/Users/499707227/QQ/WinTemp/RichOle/VYZIS%5YP[R83~0W33M4GLT.jpg[/img]
y1 y2 y3 tp
1 . 3 3    2
. . . 1    .
. . 1 2    1
data c;set b;if  y1=y2=y3 then tp=1;
if y1=y2^=y3 then tp=2;
if  y1=y3^=y2 then tp=2;
if  y2=y3^=y1 then tp=2;
if y1^=y2^=y3  then tp=3;run;
我用以上程序可以得到表格中黑色数字类型,其实我是想得到标红的数字类型,具体来讲就是y1-y3中有一个数字那么tp为1如表格第三行,空值不算!
我的程序应该怎么写了,请赐教!谢谢!

[img]file:///C:\Documents and Settings\Administrator\Application Data\Tencent\Users\499707227\QQ\WinTemp\RichOle\VYZIS%5YP[R83~0W33M4GLT.jpg[/img]

二维码

扫码加我 拉你入群

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

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

关键词:Application documents Document Settings setting 程序

沙发
akakak123 发表于 2013-8-7 10:48:30
data a;                                                                                                                                 
input y1-y3;                                                                                                                           
cards;                                                                                                                                 
1 . 3                                                                                                                                   
. . .                                                                                                                                   
. . 1                                                                                                                                   
1 1 1                                                                                                                                   
;                                                                                                                                       
run;                                                                                                                                    
data b;                                                                                                                                 
set a;                                                                                                                                 
if y1 = . and y2=. and y3=. then tp=.;                                                                                                  
else if y1 ne . and y2 ne . and y3 ne . then tp =3;                                                                                    
else if y1=y2=. or y2=y3=. or y3=y1=. then tp =1;                                                                                       
else if y1 ne . or y2 ne . or y3 ne . then tp =2;                                                                                       
run;

藤椅
tanaya 发表于 2013-8-7 11:15:10
谢谢!同时欢迎新成员加入!你可以通过每天签到赚取积分,然后兑换成金币!祝好!

板凳
tanaya 发表于 2013-8-7 11:35:52
y1         y2         y3         tp
1         .         3         2   
.         .         .         .   
.         .         1         1   
3       3       3      1
2        1      2      2
1        4      5      3
我忘记还有两种情况没有添加进去,刚应用了一下你的程序,下面两种情况实现不了,不知还有何高见?

报纸
boe 发表于 2013-8-7 14:24:27
觉得数据的呈现方式有15种,处理方式有7种,求指正,求简化
  1. data a;                                                                                                                                 
  2. input y1-y3;                                                                                                                           
  3. cards;                                                                                                                                 
  4. . . .
  5. 1 . .
  6. . 1 .
  7. . . 1
  8. . 1 1
  9. . 1 2
  10. 1 . 1
  11. 1 . 2
  12. 1 1 .
  13. 1 2 .
  14. 2 2 2
  15. 2 2 3
  16. 2 3 2
  17. 3 2 2
  18. 1 2 3
  19. ;            
  20. data c;                                                                                                                                 
  21.     set a;
  22.         if nmiss(of y1-y3)=3 then tp=0;
  23.         else if nmiss(of y1-y3)=2 then tp=1;
  24.         else if nmiss(of y1-y3)=1 then do;
  25.             if y1=y2 or y2=y3 or y3=y1 then tp=1;
  26.             else if y1^=y2^=. or y2^=y3^=. or y3^=y1^=. then tp=2;
  27.         end;
  28.         else if nmiss(of y1-y3)=0 then do;
  29.             if y1=y2=y3 then tp=1;
  30.             else if y1=y2^=y3 or y1=y3^=y2 or y2=y3^=y1 then tp=2;
  31.             else if y1^=y2^=y3 then tp=3;
  32.         end;
  33. run;
复制代码
Gorgeous girl , I love !

地板
akakak123 发表于 2013-8-7 14:29:31
data a;                                                                                                                                 
input y1-y3;                                                                                                                           
cards;                                                                                                                                 
1      .      3                                                                                                                        
.      .      .                                                                                                                        
.      .      1                                                                                                                        
3      3      3                                                                                                                        
2      1      2                                                                                                                        
1      4      5                                                                                                                        
;                                                                                                                                       
run;                                                                                                                                    
data b;                                                                                                                                 
set a;                                                                                                                                 
if y1 = . and y2=. and y3=. then tp=.;                                                                                                  
else if y1 = y2 =y3 then tp =1;                                                                                                         
else if y1=y2=. or y2=y3=. or y3=y1=. then tp =1;                                                                                       
else if y1=y2 and y3=. or y2=y3 and y1=. or y3=y1 and y2=. then tp =1;                                                                  
else if y1 = y2  or y2 = y3 or y3 = y1 then tp =2;                                                                                      
else if y1 ne y2 ne y3 and y1 ne . and y2 ne . and y3 ne . then tp =3;                                                                  
else if y1 ne . or y2 ne . or y3 ne . then tp =2;                                                                                       
run;
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
boe + 1 + 1 + 1 精彩帖子

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

7
boe 发表于 2013-8-7 16:41:54
  1. data d(drop=N);
  2.     set a;
  3.         N=nmiss(of y1-y3);
  4.         if N=3 then tp=0;
  5.         else if (N=2) or (N=1 and (y1=y2 or y2=y3 or y3=y1)) or (N=0 and y1=y2=y3) then tp=1;
  6.         else if (N=0 and y1^=y2 and y2^=y3 and y3^=y1) then tp=3;
  7.         else tp=2;
  8. run;
复制代码
Gorgeous girl , I love !

8
tanaya 发表于 2013-8-7 20:42:28
谢谢两位,两种方法都能实现。我要多尝试!

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-9 09:16