SAS中文论坛

标题: HELP!!! SAS code: create duplicate records!! [打印本页]

作者: shiyiming    时间: 2011-3-7 14:04
标题: 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!!!!
作者: shiyiming    时间: 2011-3-7 15:57
标题: Re: HELP!!! SAS code: create duplicate records!!
[code:rfqlyn6h]data b;
        set a;
        do visit=1 to days;
                output;
        end;
run;[/code:rfqlyn6h]
作者: shiyiming    时间: 2011-3-8 01:30
标题: Re: HELP!!! SAS code: create duplicate records!!
It works!

Thank you so much!!




欢迎光临 SAS中文论坛 (http://mysas.net/forum/) Powered by Discuz! X3.2