楼主: fisher163
22487 10

在SAS中产生哑变量(dummy varirable) [推广有奖]

  • 3关注
  • 5粉丝

已卖:21份资源

副教授

59%

还不是VIP/贵宾

-

威望
0
论坛币
1900 个
通用积分
16.2026
学术水平
18 点
热心指数
36 点
信用等级
17 点
经验
14861 点
帖子
409
精华
0
在线时间
1408 小时
注册时间
2007-7-12
最后登录
2025-7-11

楼主
fisher163 发表于 2009-7-12 14:57:42 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
例如x为四分类的变量,则需要产生四个哑变量(事实上分析时一般只需要纳入三个哑变量即可,以未纳入的作为reference group)

X
X1
X2
X3
X4
1
1
0
0
0
2
0
1
0
0
3
0
0
1
0
4
0
0
0
1

在SAS中实现

先建立数据集a,

data a;

input x@@;

cards;

1 2 3 4

;

run;

方法一:

data b;

set a;

x1=(x=1);

x2=(x=2);

x3=(x=3);

x4=(x=4);

run;

方法二:

data c;

set a;

array a{4} x1 x2 x3 x4;

do i= 1 to 4;

a{i}=(x=i);

end;

drop i;

run;

方法三:

data d;

set a;

if x=1 then x1=1;else x1=0;

if x=2 then x2=1;else x2=0;

if x=3 then x3=1;else x3=0;

if x=4 then x4=1;else x4=0;

run;

方法四:

data e;

set a;

array a{4} x1 x2 x3 x4;

do i= 1 to 4;

if x=1 then a{i}=i;else a{i}=0;

end;

drop i;

run;

二维码

扫码加我 拉你入群

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

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

关键词:varirable Dummy ABLE VaR ABL SAS 哑变量(dummy varirable)

回帖推荐

邓贵大 发表于2楼  查看完整内容

还有更无耻的方法,仅举两例

本帖被以下文库推荐

沙发
邓贵大 发表于 2009-7-12 22:40:52
还有更无耻的方法,仅举两例
  1. data a;
  2.     input x@@;
  3. cards;
  4. 1 2 3 4
  5. ;
  6. ods _all_ close;
  7. proc glmmod data=a prefix=x outdesign=b;
  8.     class x;
  9.     model x= x/noint;

  10. proc logistic data=a outdesign=c outdesignonly;
  11.     class x/param=glm;
  12.     model x=x/noint;
  13. run;

  14. ods listing;
  15. proc print data=b noobs;
  16. proc print data=c noobs;
  17. run;
复制代码
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

总评分: 经验 + 3  论坛币 + 3   查看全部评分

Be still, my soul: the hour is hastening on
When we shall be forever with the Lord.
When disappointment, grief and fear are gone,
Sorrow forgot, love's purest joys restored.

藤椅
fisher163 发表于 2009-7-13 08:43:01
class语句当然可以自动生成,但是不能随意设定reference group
2# 邓贵大

板凳
nernernini 发表于 2009-7-14 22:55:42
收益匪浅哈。

报纸
flutter88 发表于 2009-8-30 14:08:46
上面的方法够无耻,呵呵。

地板
txyw 在职认证  发表于 2012-9-27 16:32:10
呵呵。。。为I度
天下有我!天下有你!天下有我和你!

7
jingju11 发表于 2012-9-28 10:05:15

The way of using GLMMOD to makeclass variables dummy should be more appreciated, especially at 2009. At 2011, Ideveloped a macro to make variables dummy and its core is using GLMMOD. We haveto know that solely using GLMMOD may not be good enough because the designmatrix ignores the missing values but we don’t want to lose records beforefitting to the model. The initiative of the macro was transferring codes inPROC GLM to PROC REG for more statistical benefits limited to REG so far.

jingju

8
ryuuzt 发表于 2012-9-28 10:44:25
邓贵大 发表于 2009-7-12 22:40
还有更无耻的方法,仅举两例
学习了。感谢。

9
鱼在武汉 发表于 2013-1-16 14:48:54
十分感谢

10
阿娜塔哇 学生认证  发表于 2020-5-13 14:50:07
有没有批量处理的方法

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

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