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 (August 2004, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 31 Aug 2004 18:36:34 +0000
Reply-To:     iw1junk@COMCAST.NET
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ian Whitlock <iw1junk@COMCAST.NET>
Subject:      Re: Macro executes both 'if' & 'else' conditions
Comments: cc: Zack Haynes <Zack.Haynes@BRISTOLWEST.COM>

Zack, Your macro shows enough misunderstanding about macro and SAS to make it very hard to debug; thus it is a good example to show that a certain level of understanding is required before it is worth thinking about debugging. Macro instructions are processed during SAS compilation. Hence in the lines, else do; %put 'wait 15 minutes'; wait=%sysfunc(sleep(60*15)); %checkifpointiscompleted; end; the %PUT statement is written while the DO block is being compiled. That means it isn't in the block. Had you not commented out the next two lines, you would have seen that the %PUT statement even executed when the step could not be compiled. If SLEEP can be called by %SYSFUNC then wait=%sysfunc(sleep(60*15)); would halt the compilation (not execution) for 15 minutes. The line %checkifpointiscompleted

would be executed during compilation of the DO block. Since the code generated contains a DATA step. The previous step will finish compiling and get the error message that there is no END statement for a DO block. Now let's look at what is wanted. You want to generate a sequence of DATA steps that check a SAS data set and stop when a certain condition is met. Hence, the macro should be more like %macro checkifpointiscompleted; %local repeat ; %let repeat = YES ;

%do %until ( &repeat = NO ) ; data _null_ ; set rni50dat.soonetltrg; format pointcyc etlrundt weekdayn date9.; cycdaten=input(cycdate,8.)+19000000; pointcyc=input(put(cycdaten,8.),yymmdd8.); weekdayn=today(); if weekday(weekdayn)=1 /* sunday */ then etlrundt=today() -2; else etlrundt=today() -1; if etlrundt=pointcyc and cycledone='Y' then do ; put "Point to Daily SOON/ETL started at %sysfunc(datetime(),datetime21.)"; call symput ( "repeat" , "NO" ) ; end ; else do ; put "wait 15 minutes"; wait=sleep(60*15); end ; run ; %mend;

/* not tested */ Personally, I would want some upper bound on how many times the loop executes. The problem with the design is that SAS is tying up the system without accomplishing very much. If you stated the problem you want to solve and the operating system that you are using, I am sure that someone would give very good advice on how to solve the problem without tying up the system by using tools from the operating system. This might involve revising the code that writes RNI50DAT.SOONETLTRG. For example, that code knows when it is done and might simply write the file once when finished. Ian_Whitlock@comcast.net ======================== Date: Mon, 30 Aug 2004 18:05:53 -0400 Reply-To: Zack Haynes <Zack.Haynes@BRISTOLWEST.COM> Sender: "SAS(r) Discussion" From: Zack Haynes <Zack.Haynes@BRISTOLWEST.COM> Subject: Macro executes both 'if' & 'else' conditions Content-Type: text/plain; charset="iso-8859-1" Dear SAS-L; This macro is meant to re-execute until the date & flag conditions are met. What have I done to cause both the IF & ELSE conditions to execute? -- source -- %macro checkifpointiscompleted; data point; set rni50dat.soonetltrg; format pointcyc etlrundt weekdayn date9.; cycdaten=input(cycdate,8.)+19000000; pointcyc=input(put(cycdaten,8.),yymmdd8.); weekdayn=today(); if weekday(weekdayn)=1 /* sunday */ then etlrundt=today() -2; else etlrundt=today() -1; if etlrundt=pointcyc and cycledone='Y' then put "Point to Daily SOON/ETL started at %sysfunc(datetime(),datetime21.)"; else do; %put 'wait 15 minutes'; /* wait=%sysfunc(sleep(60*15)); */ /* %checkifpointiscompleted; */ end; %mend; %checkifpointiscompleted; run; -- log -- 61 options source mprint xwait; -- snip libnames -- 67 %macro checkifpointiscompleted; 68 data point; 69 set rni50dat.soonetltrg; 70 format pointcyc etlrundt weekdayn date9.; 71 cycdaten=input(cycdate,8.)+19000000; 72 pointcyc=input(put(cycdaten,8.),yymmdd8.); 73 weekdayn=today(); 74 if weekday(weekdayn)=1 /* sunday */ 75 then etlrundt=today() -2; 76 else etlrundt=today() -1; 77 if etlrundt=pointcyc 78 and cycledone='Y' 79 then put "Point to Daily SOON/ETL started at %sysfunc(datetime(),datetime21.)"; 80 else do; %put 'wait 15 minutes'; 81 /* wait=%sysfunc(sleep(05)); */ 82 /* %checkifpointiscompleted; */ 83 end; 84 %mend; 85 %checkifpointiscompleted; MPRINT(CHECKIFPOINTISCOMPLETED): data point; MPRINT(CHECKIFPOINTISCOMPLETED): set rni50dat.soonetltrg; MPRINT(CHECKIFPOINTISCOMPLETED): format pointcyc etlrundt weekdayn date9.; MPRINT(CHECKIFPOINTISCOMPLETED): cycdaten=input(cycdate,8.)+19000000; MPRINT(CHECKIFPOINTISCOMPLETED): pointcyc=input(put(cycdaten,8.),yymmdd8.); MPRINT(CHECKIFPOINTISCOMPLETED): weekdayn=today(); MPRINT(CHECKIFPOINTISCOMPLETED): if weekday(weekdayn)=1 then etlrundt=today() -2; MPRINT(CHECKIFPOINTISCOMPLETED): else etlrundt=today() -1; MPRINT(CHECKIFPOINTISCOMPLETED): if etlrundt=pointcyc and cycledone='Y' then put "Point to Daily SOON/ETL started at 30AUG2004:17:44:14"; MPRINT(CHECKIFPOINTISCOMPLETED): else do; 'wait 15 minutes' MPRINT(CHECKIFPOINTISCOMPLETED): end; Point to Daily SOON/ETL started at 30AUG2004:17:44:14 NOTE: There were 1 observations read from the data set RNI50DAT.SOONETLTRG. NOTE: The data set WORK.POINT has 1 observations and 6 variables. NOTE: DATA statement used: real time 0.51 seconds cpu time 0.00 seconds

-- Zac Haynes, Systems & Applications Programmer, 714-404-8840. ISPF Dialog, REXX, Scripts, SAS, Endevor, DB2, SQL, & Macro.

NOTE: THIS IS A CONFIDENTIAL COMMUNICATION. This transmission is intended only for the use of the individuals or entity to which it is addressed. If you are not the intended recipient, or the person responsible for delivering the message to the intended recipient, please return or delete it immediately. Although this e-mail and any attachments are believed to be free of any virus or other defect, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by us for any loss or damage arising in any way from its unauthorized modification or use.


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