楼主: xiulian
2310 5

[原创博文] sas判断数据集中变量的长短 [推广有奖]

  • 0关注
  • 4粉丝

博士生

28%

还不是VIP/贵宾

-

威望
0
论坛币
1899 个
通用积分
0
学术水平
8 点
热心指数
8 点
信用等级
8 点
经验
1741 点
帖子
103
精华
0
在线时间
431 小时
注册时间
2008-6-13
最后登录
2015-8-19

10论坛币
有这么个题目,数据库有73个变量,
每个变量代表某一个月的就业情况,就业情况,失业,临时工,长期工
总共有2000多个观察者,
然后老师要我们编个循环语句,要计算每个观察者分别在这三种情况得时间有多长.用一张表格表现出来

请问可以用array么????

求高手指点 谢谢

最佳答案

baoaibaobao 查看完整内容

a1 w2 t3 o4表示四个月的结业情况,其中的取值为1、2、3,分别代表失业,临时工,长期工。a b c d e代表5个观察者,b数据集中的b1表示失业的月份数,b2表示临时工月份数,b3表示长期工月份数。 最后的结果为 id b1 b2 b3 a 2 2 0 b 0 3 1 ...
关键词:数据集 array 就业情况 高手指点 循环语句 临时工 数据库 观察者 就业
沙发
baoaibaobao 发表于 2011-3-25 07:40:20 |只看作者 |坛友微信交流群
  1. data a;
  2. input id$ a1 w2 t3 o4;
  3. cards;
  4. a 1 1 2 2
  5. b 2 2 2 3
  6. c 1 2 2 2
  7. d 1 1 1 1
  8. e 2 2 1 1
  9. ;

  10. data b;
  11. set a;       
  12. array a(*) _numeric_;
  13.         b1=0;
  14.         b2=0;
  15.         b3=0;       
  16.         do i=1 to dim(a);
  17.                 if a(i)=1 then b1+1;
  18.                 if a(i)=2 then b2+1;
  19.                 if a(i)=3 then b3+1;
  20.                 end;
  21. keep id b1 b2 b3;
  22. run;
复制代码
a1 w2 t3 o4表示四个月的结业情况,其中的取值为1、2、3,分别代表失业,临时工,长期工。a b c d e代表5个观察者,b数据集中的b1表示失业的月份数,b2表示临时工月份数,b3表示长期工月份数。
最后的结果为

                                     id    b1    b2    b3

                                     a      2     2     0
                                     b      0     3     1
                                     c      1     3     0
                                     d      4     0     0
                                     e      2     2     0

使用道具

藤椅
baoaibaobao 发表于 2011-3-25 07:49:32 |只看作者 |坛友微信交流群

使用道具

板凳
xiulian 发表于 2011-3-25 18:42:36 |只看作者 |坛友微信交流群
3# baoaibaobao

谢谢楼上的回复。。。。。
dm 'clear log; clear output';
libname lib 'D:\projet sas stata';
proc contents data=lib.INSERTION;run;
data lib.question1 ;
set lib.INSERTION;  
retain;
array a(63) SIT4V01 SIT4V02 SIT4V03 SIT4V04 SIT4V05 SIT4V06 SIT4V07 SIT4V08 SIT4V019 SIT4V10 SIT4V11 SIT4V12 SIT4V13 SIT4V14 SIT4V15 SIT4V16 SIT4V17 SIT4V18 SIT4V19 SIT4V20 SIT4V21 SIT4V22 SIT4V23 SIT4V24 SIT4V25 SIT4V26 SIT4V27 SIT4V28 SIT4V29 SIT4V30 SIT4V31 SIT4V32 SIT4V33 SIT4V34 SIT4V35 SIT4V36 SIT4V37 SIT4V38 SIT4V39 SIT4V40 SIT4V41 SIT4V42 SIT4V43 SIT4V44 SIT4V45 SIT4V46 SIT4V47 SIT4V48 SIT4V49 SIT4V50 SIT4V51 SIT4V52 SIT4V53 SIT4V54 SIT4V55 SIT4V56 SIT4V57 SIT4V58 SIT4V59 SIT4V60  SIT4V61  SIT4V62  SIT4V63;
chomage=0;
enploinonaide=0;
emploi_aide=0;
inactivite=0;
do i=1 to dim(a);
if a(i)=17 then chomage=chomage+1;
if a(i)=1 then enploinonaide=enploinonaide+1;
if a(i)=2 then enploinonaide=enploinonaide+1;
if a(i)=8 then enploinonaide=enploinonaide+1;
if a(i)=9 then enploinonaide=enploinonaide+1;
if a(i)=10 then enploinonaide=enploinonaide+1;
if a(i)=11 then enploinonaide=enploinonaide+1;
if a(i)=3 then emploi_aide=emploi_aide+1;
if a(i)=4 then emploi_aide=emploi_aide+1;
if a(i)=5 then emploi_aide=emploi_aide+1;
if a(i)=6 then emploi_aide=emploi_aide+1;
if a(i)=7 then emploi_aide=emploi_aide+1;
if a(i)=13 then emploi_aide=emploi_aide+1;
if a(i)=14 then emploi_aide=emploi_aide+1;
if a(i)=12 then inactivite=inactivite+1;
if a(i)=15 then inactivite=inactivite+1;
if a(i)=18 then inactivite=inactivite+1;
end;
keep chomage emploinonaide emploi_aide inactivite;
run;
proc print;run;

这是我按照你的方法,然后修改了一下。你看看什么地方应该改进的呢????
谢谢哦

使用道具

报纸
xiulian 发表于 2011-3-25 18:43:01 |只看作者 |坛友微信交流群

使用道具

地板
xiulian 发表于 2011-3-25 19:02:58 |只看作者 |坛友微信交流群
哈哈,我知道怎么做了。。。。。。谢谢3楼啊

使用道具

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

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

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

GMT+8, 2024-5-21 15:47