Date: Wed, 24 Dec 2003 02:19:32 GMT
Reply-To: julierog@ix.netcom.com
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Roger Lustig <trovato@VERIZON.NET>
Subject: Re: string/date manipulation
Content-Type: text/plain; charset=us-ascii; format=flowed
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
>>>
>>>
|