楼主: 人生海海
2671 6

(求助)从一个数据集生成若干个子数据集 [推广有奖]

  • 0关注
  • 0粉丝

硕士生

32%

还不是VIP/贵宾

-

威望
0
论坛币
360 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1722 点
帖子
81
精华
0
在线时间
181 小时
注册时间
2005-6-15
最后登录
2014-8-21

楼主
人生海海 发表于 2009-9-22 14:11:57 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
希望能从一个数据集中按照日期(序号)每三天变量(三行)生成一个子数据集,求助各位大牛!

rq                     xh
2005-01-04       1         
2005-01-05       2         
2005-01-06       3         
2005-01-07       4         
2005-01-10       5         
2005-01-11       6         
2005-01-12       7         
2005-01-13       8         
2005-01-14       9         
2005-01-17       10
二维码

扫码加我 拉你入群

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

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

关键词:数据集 求助 数据集

回帖推荐

jingju11 发表于4楼  查看完整内容

1# 人生海海

flutter88 发表于2楼  查看完整内容

有一个笨办法 data aa1; informat rq yymmdd10.; format rq yymmdd10.; input rq xh; cards; 2005-01-04 1 2005-01-05 2 2005-01-06 3 2005-01-07 4 2005-01-10 5 2005-01-11 6 2005-01-12 7 2005-01-13 8 2005-01-14 9 2005-01-17 10 ; run; dat ...

本帖被以下文库推荐

沙发
flutter88 发表于 2009-9-22 15:07:42
有一个笨办法

data aa1;
informat rq yymmdd10.;
format rq yymmdd10.;
input rq xh;
cards;
2005-01-04       1         
2005-01-05       2         
2005-01-06       3         
2005-01-07       4         
2005-01-10       5         
2005-01-11       6         
2005-01-12       7         
2005-01-13       8         
2005-01-14       9         
2005-01-17       10
;
run;

data _null_;
set aa1 end=a;
if a=1 then call symput('total',ceil(_n_/3));
run;

%macro test;
%do i=0 %to &total;
data out&i;
set aa1 ;
if  (_n_>3*&i and _n_<=3*(&i+1)) then output out&i;
%end;
%mend;

%test;
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

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

藤椅
人生海海 发表于 2009-9-23 00:54:10
非常感谢,解决了我的大问题!

2# flutter88

板凳
jingju11 发表于 2009-9-23 07:31:37
1# 人生海海


  1. data _null_;
  2. set aa1 end=_endof;
  3. if _endof then call symput('total',put(ceil(_n_/3), 10.));
  4. run;
  5. %macro subsets;
  6. data %do i=1 %to &total; out&i  %end;;
  7.   set aa1;
  8.   if _n_ <=3 then  output out1;
  9.   %if &total>1 %then%do;
  10.    %do i=2 %to &total;
  11.     else if _n_ <=3*&i then output out&i;
  12.    %end;
  13.   %end;
  14. run;
  15. quit;
  16. %mend subsets;

  17. %subsets
  18. ;
复制代码
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

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

报纸
flutter88 发表于 2009-9-23 09:33:13
4# jingju11

强,这样效率改进很多了,呵呵

地板
爱萌 发表于 2009-9-23 15:28:03
data _null_;

set aa1 end=_endof;

if _endof then call symput('total',put(ceil(_n_/3), 10.));

run;

%macro subsets;

data %do i=1 %to &total; out&i  %end;;

  set aa1;

  if _n_ <=3 then  output out1;

  %if &total>1 %then%do;

   %do i=2 %to &total;

    else if _n_ <=3*&i then output out&i;

   %end;

  %end;

run;

quit;

%mend subsets;



%subsets

;

好样的
最恨对我说谎或欺骗我的人

7
lion_li 发表于 2009-9-23 22:16:49
proc sql noprint;select count(*) into:  n from aa1;quit;
%macro create;
  %do i=1 %to &n;
    %if %sysfunc(mod(&i,3))=0 %then %do;
    data temp%sysfunc(compress(%eval(&i/3)));
        set temp;
    if _n_>%eval(&i-3) and _n_<=&i then output;
        run;
    %end;
  %end;
%mend create;
%create;

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

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