Date: Mon, 6 Dec 2010 15:12:29 -0500
Reply-To: Chang Chung <chang_y_chung@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Chang Chung <chang_y_chung@HOTMAIL.COM>
Subject: Re: %sysfunc
On Mon, 6 Dec 2010 14:42:46 -0500, Jeff <zhujp98@GMAIL.COM> wrote:
>code:
> firstdateofsrv>=%sysfunc(intnx(month,%sysfunc(inputN(%sysfunc(dequote
(&start)),mmddyy10)),1),mmddyy10)
>
>
>log:
>
>MPRINT(GETCLAIMSDATA): create table data.BSC_Med_Claim as select *from
>connection to OLEDB (
>select * from dw1.BSC_DBOR.dbo.BSC_MED_CLAIM where
>firstdateofsrv>=02/01/2009
>
>*I want *%sysfunc(intnx(month,%sysfunc(inputN(%sysfunc(dequote
(&start)),mmddyy10)),1),mmddyy10)
>to be resolved to '02/01/2009' not 02/01/2009
>how can I do that?
...
hi, jeff,
When handling dates and date literals in macro, I found that it is helpful
to have a couple of very simple utility macros. Hope this helps a bit.
Cheers,
Chang
%*-- utilities --*;
%macro date2num(date, informat=anydtdte.);
%*-- strip quotations and postfix d from date literal if any. --*;
%*-- quotations are intentionally doubled to prevent unmatched error --*;
%let date=%sysfunc(prxchange(s/[''""]d?//i,-1,&date));
%sysfunc(inputn(&date,&informat))
%mend date2num;
%macro num2date(num, format=date10., literal=1);
%local n;
%let n = %sysfunc(putn(&num,&format));
%if &literal %then "&n"d; %else &n;
%mend num2date;
%*-- example usage --*;
%let start = "12/6/2010"d;
%macro srv1(start);
%local nstart nsrv1;
%let nstart = %date2num(&start, informat=mmddyy10);
%let nsrv1 = %sysfunc(intnx(mon, &nstart, 1));
%num2date(&nsrv1, format=mmddyy10)
%mend srv1;
%put start=&start srv1=%srv1(&start);
%*-- on log
start="12/6/2010"d srv1="01/01/2011"d
--*;
|