LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2003, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 23 Dec 2003 22:04:49 -0500
Reply-To:     Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Subject:      Re: string/date manipulation

How about giving the macro a keyword parameter through which one can pass any reference date, and having it use TODAY() as the default?

On Wed, 24 Dec 2003 02:19:32 GMT, Roger Lustig <trovato@VERIZON.NET> wrote:

>Gerhard, David: > >That ought to work. A few features of SAS that can simplify the process >even more: >--the DDMMYYxw. formats >--the alignment parameter in INTNX >--the YYMMxw. formats >--alternatively, the DATE9. format. > >data _null_; >firstday=intnx("month",today(),0); /* or whatever */ >length mydate $11; > >call symput('TABLE',put(firstday,yymmn6.)); > > >mydate=put(firstday,ddmmyyd10.); >datechar=substr(mydate,1,3) || > upcase(put(firstday,monname3.)) || > substr(mydate,6,5); > > >***************** Alternative for the previous 2 statements; >*mydate=put(firstday,date9.); >*datechar=substr(mydate,1,2) || '-' || > substr(mydate,3,3) || '-' || > substr(mydate,6,4); >****************** End alternative ************************; ><etc.> > >lastday=intnx('month',today(),0,'E'); *** The alignment parameter!; > ><etc.> > >OK? > >Roger (for G-d, for country, and formats!) > >Gerhard Hellriegel wrote: >> I think that could be a macro what brings some help. >> Something like that: >> >> %macro a; >> data _null_; >> today=intnx("month",today(),0); /* or whatever */ >> day=day(today); >> month=month(today); >> year=year(today); >> call symput("table",compress(put(year,4.)!!put(month,z2.))); >> monname=upcase(put(today,monname3.)); >> datechar=put(day,z2.)!!"-"!! >> monname!! "-"!! >> put(year,4.); >> call symput("start","'"!!datechar!!"'"); >> day=day(intnx("month",today,+1)-1); >> datechar=put(day,z2.)!!"-"!! >> monname!! "-"!! >> put(year,4.); >> call symput("end","'"!!datechar!!"'"); >> run; >> >> /* now you have all you need...*/ >> /* >> proc sql; >> connect to oracle (.......); >> create table table&table as select * from connection to oracle >> (select id, name from mastertable where trunc(date) between >> &start and &end); >> */ >> %put &start &end &table; >> %mend; >> options symbolgen; >> %a; >> >> >> >> >> >> >> >> On Tue, 23 Dec 2003 03:00:51 GMT, Roger Lustig <trovato@VERIZON.NET> wrote: >> >> >>>David: >>> >>>a) running SAS on a monthly basis is a bad idea. Whenever I do that, I >>>forget all the good stuff from month to month and have to learn it all >>>over again. >>> >>>b) The job you specify below looks like it ought to be run in January >>>2004. If that's the case, then a few formats, the INTNX function, and a >>>little macro programming should reduce your monthly effort to a mere >>>wave of the hand and a tap on the ENTER key. >>> >>>c) Oh, and the today() function. >>> >>>Enjoy! >>> >>>Roger >>> >>> >>>David Chang wrote: >>> >>>>Hi, I am running SAS on a monthly basis. Every time when I need to >> >> execute >> >>>>the scripts, I need to modify the date values in my code (as below): >>>> >>>>proc sql; >>>>connect to oracle (.......); >>>> create table table200312 as select * from connection to oracle >>>> (select id, name from mastertable where trunc(date) between >>>>'01-DEC-2003' and '31-DEC-2003'); >>>>disconnect from oracle; >>>>quit; >>>> >>>>So, for a simple query like above, I have to modify three strings >>>>table200312 >>>>'01-DEC-2003' >>>>'31-DEC-2003' >>>> >>>>Is there a way to automate the analysis by setting up some string >> >> variables? >> >>>>Your help will be greatly appreciated !! >>>> >>>>David >>>> >>>>


Back to: Top of message | Previous page | Main SAS-L page