全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1391 4
2011-12-30
悬赏 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 ...
二维码

扫码加我 拉你入群

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

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

全部回复
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;
二维码

扫码加我 拉你入群

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

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

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;
二维码

扫码加我 拉你入群

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

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

2011-12-30 10:12:29
谢谢楼上,为什么group by 1,2 行,group by sex不行呢?

我的实际数据n多分类呢
二维码

扫码加我 拉你入群

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

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

2011-12-30 10:16:24
不对啊,我的目的是想把男性的所有年龄取值读到一起,例如:

F 11,12,13,14,15
二维码

扫码加我 拉你入群

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

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

栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群