Date: Mon, 22 Nov 2004 10:20:19 -0800
Reply-To: Dennis Diskin <diskin@SNET.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Dennis Diskin <diskin@SNET.NET>
Subject: Re: Macro to create multiple dates from numeric fields in one
data set
In-Reply-To: <200411221756.iAMHu1Dm024397@listserv.cc.uga.edu>
Content-Type: text/plain; charset=us-ascii
Amanda,
Just a slight alteration to make the macro not contain the datastep itself, but only the code for the variables of interest:
%macro datechng (txname,txlabel);
&txname._start = mdy(&txname.sm,&txname.sd,&txname.sy);
&txname._end= mdy(&txname.em,&txname.ed,&txname.ey);
format &txname._start &txname._end mmddyy.;
label &txname._start = "&txlabel Start Date"
&txname._end = "&txlabel End Date";
drop &txname.sm &txname.sd &txname.sy
&txname.em &txname.ed &txname.ey;
%mend;
data int1_ltfu;
set req4016.med45all;
%datechng (alpha, Alpha Blocker);
%datechng (beta, Beta Blocker);
etc.....
run;
HTH,
Dennis Diskin
Amanda Reno <areno@UROLOGIX.COM> wrote:
Hi everyone,
I am a beginner and need help with writing a macro. I work for a medical
company and have been asked to look at alternative treatment data in an old
database. The genius who created the database, set the dates up as 3
separate numeric fields for month/day/year, rather than creating a date
field. So, my first step is to create actual date fields out of this, so
that we can calculate how many weeks elapsed between enrollment and
alternative treatment. Here is the macro I wrote to create the fields:
***********************************
/* Converts startmonth/day/year & endmonth/day/year to actual date fields
*/
%macro datechng (txname,txlabel);
data int1_ltfu;
set req4016.med45all;
&txname._start = mdy(&txname.sm,&txname.sd,&txname.sy);
&txname._end= mdy(&txname.em,&txname.ed,&txname.ey);
format &txname._start &txname._end mmddyy.;
label &txname._start = "&txlabel Start Date"
&txname._end = "&txlabel End Date";
drop &txname.sm &txname.sd &txname.sy
&txname.em &txname.ed &txname.ey;
/*Old numeric fields dropped now that new date fields are created
*/
run;
%mend;
%datechng (alpha, Alpha Blocker);
************************************
This code appears to work correctly. My real problem is: I have a total of
8 treatment types that need their start & end dates converted, and I want
the converted dates to all be in the same dataset. I've looked at code
created by my predecessors that has some similarities. However, their code
would create a new dataset each time the macro is run (instead of the
second line in my code being 'data int1_ltfu', it would be 'data
&txname'). Then, once the 8 'data &txname' datasets had been created, the
code would merge them into a single one.
This seems inefficient to me. Surely there is some way that this macro can
be re-written so that I don't have to go through this merge step?
I've done a little looking through the SAS-L archives and in my SAS books,
but my boss asked me to stop to work on an emergency project right now...so
if anyone can suggest a solution, or point me to a previous post with a
solution, I would really appreciate it. Thank you for helping out a newbie!
Amanda