SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

12
返回列表 发新帖
楼主: shiyiming
打印 上一主题 下一主题

请问数据集的转换问题

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
11#
 楼主| 发表于 2004-3-4 10:17:07 | 只看该作者

我作了一点小修改

xic,我把你的程序稍微改动了一下,但是我不太明白为什么不能达到预期效果,请指教
data a;
input a b c r;
datalines;
1 5 4 22
1 5 4 4
1 5 4 9
1 5 4 22
1 5 4 4
1 5 4 9
2 7 3 11
2 7 3 5
2 7 3 7
2 7 3 11
;

proc sql;
create table a as
select *, count(*) as cnt
from a
group by a, b, c;
quit;

%macro expand;
%global count;

proc sql noprint;
select max(cnt) into :maxcnt
from a;
quit;

data b(drop=r);
retain
%do i=1 %to &maxcnt;
r&i
%end;;
set a;
by a b c;
if first.c then do;
%do i=1 %to &maxcnt;
r&i=.;
%end;
%let count=1;
r&count=r;
end;
else do;
%let count=count+1;
r&count=r;
end;
if last.c then output;
run;

%mend;

%expand;
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
12#
 楼主| 发表于 2004-3-4 22:11:34 | 只看该作者
I think you have mixed up the macro variable with a SAS variable in data step.  Is COUNT a macro variable or variable in data step, in either way, the line %let count=count+1 will not work.
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
13#
 楼主| 发表于 2004-3-5 20:00:23 | 只看该作者
[quote="willon":5bc30]proc transpose data=tem out=tem1(drop=_name_) prefix=r;
by a b c;
run;[/quote:5bc30]

I think Willon's solution is one of the best (simple and common), providing the data set is sorted by a b c, and the the number of r(r1,r2,...,rn) is smaller than 32764 (SAS on windows platform).
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2025-5-3 04:37 , Processed in 0.076939 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表