楼主: niuwussc
1202 4

[原创博文] 怎么把变量取值情况读取到新表中? [推广有奖]

  • 0关注
  • 0粉丝

本科生

19%

还不是VIP/贵宾

-

威望
0
论坛币
1107 个
通用积分
1.0500
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1738 点
帖子
52
精华
0
在线时间
103 小时
注册时间
2005-10-26
最后登录
2024-3-15

10论坛币
我用以下程序可以将数量按照sex的不同分组,存储到新表中。 请问怎么把age的值也存储过去呢?

proc sql;create table tt as select sex,count(distinct age) as numberfrom sashelp.class;quit;
proc sort in=tt out=tt noduplicates; by _all_; run;

我只会使用下面这个sql读,不会存储新表,请各位帮助,谢谢。

proc sql;select distinct age into :range separated by ','from sashelp.class;quit;

最佳答案

maidenhan 查看完整内容

Now, I may get the point. Try again, please. proc sort data = sashelp.class out = temp01; by age; run; data _null_; format age_list $100.; if _n_ = 1 then do; dcl hash h(); h.definekey("sex"); h.definedata("sex","age_list"); h.definedone(); end; set temp01 end=eof; if h.find()=0 then do; if find(age_list,compress(age)) = 0 then do; age_list = compress(age_list ...
关键词:duplicates duplicate proc sql Distinct separate
沙发
maidenhan 发表于 2011-12-30 09:12:42 |只看作者 |坛友微信交流群
niuwussc 发表于 2011-12-30 10:16
不对啊,我的目的是想把男性的所有年龄取值读到一起,例如:

F 11,12,13,14,15
Now, I may get the point. Try again, please.

proc sort data = sashelp.class out = temp01;
        by age;
run;
data _null_;
        format age_list $100.;
        if _n_ = 1 then do;
                dcl hash h();
                h.definekey("sex");
                h.definedata("sex","age_list");
                h.definedone();
        end;
        set temp01 end=eof;
        if h.find()=0 then do;
                if find(age_list,compress(age)) = 0 then do;
                        age_list = compress(age_list||","||age);
                        h.replace();
                end;
        end;else do;
                age_list = age;
                h.add();
        end;
        if eof then h.output(dataset:"temp02");
run;

使用道具

藤椅
maidenhan 发表于 2011-12-30 10:00:35 |只看作者 |坛友微信交流群
Maybe the following code would be a little help.
proc sql;
        create table temp as
        select sex, age, count(distinct age) as number
                from sashelp.class
                group by 1, 2;
quit;

使用道具

板凳
niuwussc 发表于 2011-12-30 10:12:29 |只看作者 |坛友微信交流群
谢谢楼上,为什么group by 1,2 行,group by sex不行呢?

我的实际数据n多分类呢

使用道具

报纸
niuwussc 发表于 2011-12-30 10:16:24 |只看作者 |坛友微信交流群
不对啊,我的目的是想把男性的所有年龄取值读到一起,例如:

F 11,12,13,14,15

使用道具

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

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

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

GMT+8, 2024-4-29 01:39