楼主: redaring
5892 8

请教关于 proc tabulate 的问题 [推广有奖]

  • 0关注
  • 0粉丝

硕士生

21%

还不是VIP/贵宾

-

威望
0
论坛币
48 个
通用积分
0.0600
学术水平
0 点
热心指数
1 点
信用等级
0 点
经验
4910 点
帖子
102
精华
0
在线时间
123 小时
注册时间
2009-11-22
最后登录
2018-2-15

楼主
redaring 发表于 2009-12-29 13:37:18 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
我有一组如下格式的数据,想要统计频数,用来proc tabulate,可是还是没法达到我想要的效果,想请高人指点一下:

stas year month day tem
123 1951 1 1 2
123 1951 1 2 2
123 1951 2 1 2
123 1951 2 2 2
123 1951 3 1 2
123 1951 3 2 2
123 1952 1 1 2
123 1952 1 2 2
123 1952 2 1 2
123 1952 2 2 2
123 1952 3 1 2
123 1952 3 2 2
123 1953 1 1 2
123 1953 1 2 2
123 1953 2 1 2
123 1953 2 2 2
123 1953 3 1 2
123 1953 3 2 2
246 1951 1 1 2
246 1951 1 2 2
246 1951 2 1 2
246 1951 2 2 2
246 1951 3 1 2
246 1951 3 2 2
246 1952 1 1 2
246 1952 1 2 2
246 1952 2 1 2
246 1952 2 2 2
246 1952 3 1 2
246 1952 3 2 2
246 1953 1 1 2
246 1953 1 2 2
246 1953 2 1 2
246 1953 2 2 2
246 1953 3 1 2
246 1953 3 2 2
789 1951 1 1 2
789 1951 1 2 2
789 1951 2 1 2
789 1951 2 2 2
789 1951 3 1 2
789 1951 3 2 2
789 1952 1 1 2
789 1952 1 2 2
789 1952 2 1 2
789 1952 2 2 2
789 1952 3 1 2
789 1952 3 2 2
789 1953 1 1 2
789 1953 1 2 2
789 1953 2 1 2
789 1953 2 2 2
789 1953 3 1 2
789 1953 3 2 2

我自己写的语句是这样的:

proc tabulate data=test.test1 out=test.test2;
class stas tem year;
table stas*tem,year all;
run;

output 出来的结果:

数据集是这样的:


我希望数据集最后出来的结果和output的格式是类似的,也就是把原来变量 year 的值作为新的数据集里的变量名,而且type of , page for, table for 这几个我不想要,只想要 例如 当stas=123 时,tem=1 在 year=1951 时出现的频数。

希望哪位大侠可以帮帮忙,叩谢哦!
二维码

扫码加我 拉你入群

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

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

关键词:Tabulate Late Abu ATE tab 请教 proc Tabulate

回帖推荐

xuwei2007 发表于8楼  查看完整内容

proc sql; create table t as select stas, tem, year, count(year) as n from test1 group by stas,tem, year; quit; proc transpose data=t out=t1; by stas tem; var n; id year; run;

本帖被以下文库推荐

沙发
wyxlls725 发表于 2009-12-29 14:09:36
data test2;
set sasuser.test2;
keep stas tem year n;
run;
你试一下看是你想要的吗?

藤椅
wyxlls725 发表于 2009-12-29 14:10:04
复制到一个新的数据集中,只保存你想要的那几个!

板凳
redaring 发表于 2009-12-29 14:22:09
谢谢 wyxlls725 ,我试过了,可以删掉多余的变量,但是还是不能以year的值作为新的变量名。我想要的效果是这样的:

stas    tem    1951    1952    1953
123    1          2            1          0
123    2          4            5          6
246    1          1            1           1
246    2          5            5          5

盼哪位高人指点一下啦!

报纸
bobguy 发表于 2009-12-29 15:18:21
4# redaring

If you do as   year=' ' * n=' ' in you table statement, you will get exactly what you want in output.

HTH

proc tabulate data=test1 ;
class stas tem year;
table stas*tem,year=' ' * n=' ' ;
run;

地板
redaring 发表于 2009-12-29 15:38:40
谢谢 bobguy,试了一下,在output 中果然实现了我想要的结果,非常感谢!
但是在新输出的数据集中仍然是和原来一样的,year仍然是一列,这个该怎么解决呢?

7
bobguy 发表于 2009-12-29 15:53:12
6# redaring

If you want a data set that looks like the output, you may need to tranpose the output data. The transpose can be done with several approaches.

Hope This helps.

8
xuwei2007 发表于 2009-12-29 16:37:16
proc sql;
   create table t as
   select  stas, tem, year, count(year) as n
   from test1
   group by stas,tem, year;
quit;


proc transpose data=t out=t1;
    by stas tem;
    var n;
   id year;
run;
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

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

9
redaring 发表于 2009-12-29 19:46:42
谢谢bobguy的建议,于是我尝试把行列置换,可因为自己是新手,一直没成功弄出来,呵呵。

非常感谢 xuwei2007, 用你写的语句终于把问题解决了,好好学习了一下,谢谢了!

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

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