作者imaltar (..)
站内Statistics
标题Re: [程式] sas资料选取问题
时间Thu Jun 24 12:14:41 2010
※ 引述《richubby》之铭言:
: SAS
: [程式问题]:
: 资料处理
: [软体熟悉度]:
: 低(1~3个月)
: [问题叙述]:
: 最近在跑资料的时候遇到一些问题想请问板上高手
: 公司代码 日期 A变数
: 4212 20090415 0.15
: 3232 20090416 1.23
: 1101 20090417 2.33
: 9232 20090418 1.66
: 8422 20090512 2.36
: 1102 20090612 1.42
: 6473 20090613 2.42
: ...
: ..
: .
: 想要抓1101公司20090417前的日期
: 与1102公司20090612前的日期
: 不知道问题有没有讲得很清楚..还是先谢谢大家了!
: 希望的结果↓
: 1101 20090415
: 1101 20090416
: 1101 20090417
: 1102 20090415
: 1102 20090416
: 1102 20090417
: 1102 20090418
: 1102 20090512
: 1102 20090612
: ...
: ..
: .
: 谢谢大家:D
data test;input comp_id date yymmdd8. a;
format date yymmddn8.;
cards;
4212 20090415 0.15
3232 20090416 1.23
1101 20090417 2.33
9232 20090418 1.66
8422 20090512 2.36
1102 20090612 1.42
6473 20090613 2.42
;
run;
%macro date(comp_id=,n=);
data _null_;set test(where=(comp_id in (&comp_id.)));
call symput('date',date);run;
data test&n.;set test(keep=date);comp_id=&comp_id.;if date <= &date.;run;
%mend;
%date(comp_id=1101,n=1);
%date(comp_id=1102,n=2);
data test;set test1 test2;
proc sort data=test;by comp_id date;run;
comp_id就是公司名,n=1表示产生test1这个资料,内容是comp_id=1101时日期小於
20090417的结果
最後的test合并test1 test2就是你想要的资料
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.43.125.210
1F:推 richubby:yeah 已经收到了 很谢谢您:) 06/24 12:27
2F:→ richubby:我们可能需要花一点时间去解读一下巨集 哈哈" 06/24 12:28