SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 529|回复: 2
打印 上一主题 下一主题

HELP!!! SAS code: create duplicate records!!

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2011-3-7 14:04:28 | 只看该作者

HELP!!! SAS code: create duplicate records!!

Hi everyone,

I have a question about creating duplicate records (but different times) using SAS.

my questions is:
If I have a dataset like
days              startdate                  stopdate
2                  01/02/2009              03/02/2009
3                  05/02/2009              08/02/2009
5                  01/03/2009              06/03/2009

I want to duplicate the first record two times and duplicate the second record three times....., how should I write SAS code? The real case is there are so many records(50), and I want repeat every records different times according the number in front of the record! Also I want to create a NEW COLUMN below (visit)!!

Want to output dataset like:
days                  startdate                   stopdate              visit
2                       01/02/2009               03/02/2009             1
2                       01/02/2009               03/02/2009             2
3                       05/02/2009               08/02/2009             1
3                       05/02/2009               08/02/2009             2
3                       05/02/2009               08/02/2009             3
5                       01/03/2009               06/03/2009             1
5                       01/03/2009               06/03/2009             2
5                       01/03/2009               06/03/2009             3
5                       01/03/2009               06/03/2009             4
5                       01/03/2009               06/03/2009             5

I didn't find the similar problem online, so I hope I could get help here^^
Thanks so much!!!!
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
沙发
 楼主| 发表于 2011-3-7 15:57:15 | 只看该作者

Re: HELP!!! SAS code: create duplicate records!!

[code:rfqlyn6h]data b;
        set a;
        do visit=1 to days;
                output;
        end;
run;[/code:rfqlyn6h]
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
板凳
 楼主| 发表于 2011-3-8 01:30:22 | 只看该作者

Re: HELP!!! SAS code: create duplicate records!!

It works!

Thank you so much!!
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-11 11:06 , Processed in 0.069905 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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