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 2005, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 9 Aug 2005 16:28:20 +0200
Reply-To:     Andre Wielki <wielki@INED.FR>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Andre Wielki <wielki@INED.FR>
Subject:      Re: comma(,) mask problem: ERROR: Macro function %INDEX has too
              many arguments.
Comments: To: Chang Chung <chang_y_chung@HOTMAIL.COM>
In-Reply-To:  <200508091408.j79E8qgo022791@listserv.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Ok Chang in my too quickly answer, i was making confusion about the list of spec char including "|" as equivalent to the mnemonic or

but if you try this changing one letter more no==> ne in the parameter passed

could you explain the difference of behavior between your solution and that with %quote

105 %macro test(leftname=); 106 %put beginning: leftname=&leftname; 107 %let b=%index(&leftname,|); 108 %put b=&b; 109 %let leftname=%qsubstr(&leftname,%index(&leftname,|)+1); 110 %put ok: after first index function: leftname=&leftname; 111 %put check index function after leftname is changed?; 112 %let b=%index((&leftname),|); 113 %put b=&b; %put ok: why?; 114 %mend; 115 %test(leftname=%str(||if ne, primary:)) beginning: leftname=||if ne, primary: b=1 ok: after first index function: leftname=|if ne, primary: check index function after leftname is changed? b=2 ok: why?

with %let b=%index(%quote(&leftname),|); give us in any case beginning: leftname=||if ne, primary: b=1 ok: after first index function: leftname=|if ne, primary: check index function after leftname is changed? b=1 ok: why?

Andre

Chang Chung wrote:

> > A good question! It is important to know the reason why the first %index > function works fine and the second does not. The lesson here is that: > > once quoted, a string remains quoted, unless you unquote it. > > Since you are quoting the comma when you invoke the macro using %str(), it > remains being quoted when the first %index() is called. This is why the > first %index works fine. > > Now, in the middle, you are using %substr() function and it returns > *unquoted* text. And you are assigning this unquoted text back to the macro > variable leftname. So, this point on, the leftname has unquoted comma. It > does not cause any trouble in the %put line, but it does in the second call > to %index. Since %index now sees two commas. > > The remedy I would recommend is to use %qsubstr(), which returns quoted test. > > Cheers, > Chang > > %macro test(leftname=); > %put beginning: leftname=&leftname; > %let b=%index(&leftname,|); > %put b=&b; > %let leftname=%qsubstr(&leftname,%index(&leftname,|)+1); /* fixed! */ > %put ok: after first index function: leftname=&leftname; > %put check index function after leftname is changed?; > %let b=%index(&leftname,|); > %put b=&b; > %put ok; > %mend; > %test(leftname=%str(||IF NO, PRIMARY FOR STUDY COMPLETION:)); > /* on log: > beginning: leftname=||IF NO, PRIMARY FOR STUDY COMPLETION: > b=1 > ok: after first index function: leftname=|IF NO, PRIMARY FOR STUDY COMPLETION: > check index function after leftname is changed? > b=1 > ok > */ >

-- Andre Wielki INED (Institut National d'Etudes Démographiques) 133 Boulevard Davout 75980 Paris Cedex 20 33 (0) 1 56 06 21 54 FRANCE


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