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 (November 1998, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 19 Nov 1998 09:19:28 -0500
Reply-To:     WHITLOI1 <WHITLOI1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         WHITLOI1 <WHITLOI1@WESTAT.COM>
Subject:      Re: A macro looping error
Comments: To: "Raymond V. Liedka" <liedka@UNM.EDU>
Content-Type: text/plain; charset=US-ASCII

Subject: A macro looping error Summary: ; Respondent: Ian Whitlock <whitloi1@westat.com>

Raymond V. Liedka <liedka@UNM.EDU> wondered what was wrong with his macro code:

> 1 > 2 %macro words(string); > 3 %local count word; > 4 %let count=1; > 5 %let word=%qscan(&string,&count,%str( )); > 6 %do %while(&word ne); > 7 %let count=%eval(&count+1); > 8 %let word=%qscan(&string,&count,%str( )); > 9 %end; > 10 %eval(&count-1); > 11 %mend words; > 12 > 13 > 14 %macro makedata; > 15 > 16 > 17 %let varlist= > 18 TOP.CP.$.GNP.PCAP > 19 TOP.KP.$.GNY.PCAP > 20 TOP.KP.$.GDI.PCAP > 21 CP.$.GNP.CAP > 22 PR.POPN > 23 NET.INVEST.DIRECT > 24 ; > 25 > 26 %let nvars=%words(&varlist); > 27 > 28 > 29 %do i=1 %to &nvars; > 30 %let thisvar=%qscan(&varlist,&i,%str( )); > 31 %put &thisvar; > 32 %end; > 33 > 34 %mend makedata; > 35 > 36 %makedata; > > ERROR: A character operand was found in the %EVAL function or %IF >

Diane Rhodes <RHODESD1@WESTAT.COM> and Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK> both gave solutions to his "real" problem, but I am more interested in why the macro code did not work.

Stan Li <sas_sph@YAHOO.COM> made the same mistake in his improved word counter:

> %macro words(string); > %* to count the words in the input string; > %eval(%length(&string)- > %length(%sysfunc(compress(&string))) + 1); > %mend words;

There is no looping error. The mistake is on line 10. The macro WORDS should produce a count. As given it produces a count plus a semicolon. Unfortunately I cannot find a plausible explanation why the extra semicolon should cause line 26 to fail, but it does. Can anyone explain why?

Ian Whitlock


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