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 (May 2001, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sat, 26 May 2001 21:54:05 -0000
Reply-To:     sashole@bellsouth.net
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Paul Dorfman <paul_dorfman@HOTMAIL.COM>
Subject:      Re: %do loop
Comments: To: Brad.Goldman@AUTOTRADER.COM
Content-Type: text/plain; format=flowed

Brad,

I assume that your %DO-loop is actually enclosed in some kind of macro, for I doubt it would work in the open code. As to the main question, after you have assigned the FROM and TO loop values to the resolved values of the macro variables YESTERDAY and DAYONE, to SAS they become merely the start and end values for the loop index I. Thus what you are printing is the index values from 501 on, and since SAS does not care about preceding the loop index values with anything but nothing, that is what you see displayed.

Now if you really need to see the index values printed with leading zeroes (as I would, too, if I needed to look at MMDD values), you should format them accordingly. For instance:

92 %Macro A ; 93 %Put ---- ; 94 %Do I = &Dayone %To &Yesterday ; 95 %Put %Sysfunc (Int(&I), Z4.) ; 96 %End; 97 %Mend ; 98 %A ---- 0501 0502 .... 0525

You might ask why above, (Int(&I),Z4.) was used instead of perhaps the more conventional (PutN(&I, Z4.)). Just cause. It does not really matter what function to use, the only requirement for it being to leave the &I value intact. For an integer, INT is as good as FLOOR, CEIL, SUM, MIN, MAX, MEAN, and heck knows what else.

Finally, whilst I believe that your reasons to program the way you have illustrated must be convincing, it is not the less hard to picture why would one need to print the values in the log in this manner, as they are perfectly printable from the Data step where they were born. I mean, would it not be easier to do it, for example, this way:

Data _Null_; Do Date = Intnx ('Month', Date()-1 , 0) To Date()-1 ; Put Date MMDDYY4. ; End; Run;

Kind regards, ========================= Paul M. Dorfman Jacksonville, Fl =========================

>From: "Goldman, Brad (AT-Atlanta)" <Brad.Goldman@AUTOTRADER.COM> >I have the following %do loop in my code (greatly simplified to illustrate) >--------------------- >data _null_; >call symput('yesterday',substr(put(today()-1,yymmdd6.),3,4)); >call symput('dayone',substr(put(intnx('month',today()-1,0),yymmdd6.),3,4)); >run; > >%put _user_; >%do i = &dayone %to &yesterday; >%put &i; >%end; >----------------------- >Which generates the following output: >GLOBAL DAYONE 0501 >GLOBAL YESTERDAY 0525 >501 >502 >... >524 >525 >-------------------------- >My question/problem is this: What happened to the leading zero that >&yesterday and &dayone had, and how can I keep these zeros in front of the >date when it goes through the loop? I need to append a bunch of datasets >together of the form wc.wc<mmdd> for the current month. > >Any help appreciated! >Thank you, >Brad Goldman

_________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com


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