Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP!!! Create Duplicate records using SAS!

Status
Not open for further replies.

zxlsupergirl48

Programmer
Mar 6, 2011
7
0
0
US
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 couldn't find similar problems solutions, so I hope I could get help here^^
Thanks so much!!!!
 
Try something like this to take firstTable and turn it into the larger secondTable (both in WORK library). The "greater-equal" comparison makes sure you do not have an endless loop on days smaller 1.

Code:
data WORK.secondTable;
  set work.firstTable;
  length visit 8;
  visit = 1;
  do until (visit ge days);
    output;
    visit = visit + 1;
  end;
run;
 
Have a blast at this

data Duplics ;
set Whatever;
do visit = 1 to days;
output;
end;
run;
 
Thanks a lot!

Actually, that's the way I choose to use in this real case finally!:)
 
@jj72uk d(^_^)b shorter, true. Always forget about "do" w/o init and inc lines. Back to the tele again, "supernatural-on-dvd" time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top