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 (March 2003, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sat, 1 Mar 2003 11:49:18 -0500
Reply-To:     "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Subject:      Re: Translate double quote to single quote in a macro variable ?
              (thanks & further question)

Ya:

When a function is invoked via %sysfunc, literal character arguments are not to be quoted.

translate is TRANSLATE(source,to-1,from-1<,...to-n,from-n>)

%sysfunc(translate(&a,'"',"'")) is requesting three things change DOUBLE QUOTE to SINGLE QUOTE change SINGLE QUOTE to DOUBLE QUOTE change DOUBLE QUOTE to SINGLE QUOTE

If the quotes were needed (as when used in a data step), the translation requested would be change SINGLE QUOTE to DOUBLE QUOTE ! not quite what you wanted in the first place.

It was only by chance that the apparent mis-specification of yielded expected result.

A more proper invocation would be %sysfunc (translate (&a,%str(%'),%str(%")))

tranwrd is TRANWRD(source,target,replacement)

You function invocation from %sysfunc() again uses quotes, which are not needed (and were passed literally to the function)

%sysfunc(tranwrd(<source>,\,\\)) would suffice.

%sysfunc(tranwrd(<source>,'\','\\')) is equivalent to data step invocation tranwrd(<source>, "'\'", "'\\'")

&a does not contain the literal sequence SINGLE QUOTE-BACK SLASH-SINGLE QUOTE and thus never finds target to replace (with the also incorrectly 'over-quoted' argument SINGLE QUOTE-BACK SLASH-BACK SLASH-SINGLE QUOTE )

-- Richard A. DeVenezia, http://www.devenezia.com "Huang, Ya" <yhuang@AMYLIN.COM> wrote in message news:9312B0A3065FA54EAB5A4D399EF96346EB128B@api-exch-1.amylin.com... > Harry, > > Now I need to make b's value = Program 'L:\\xxx\\yyy\\zzz.sas', so I tried: > > 202 %let a=Program "L:\xxx\yyy\zzz.sas"; > 203 %let b=%sysfunc(tranwrd(%sysfunc(translate(&a,'"',"'")),'\','\\')); > 204 %put &b; > Program 'L:\xxx\yyy\zzz.sas' > > 205 > 206 data _null_; > 207 b=tranwrd(translate(symget('a'),"'",'"'),'\','\\'); > 208 call symput('b',b); > 209 run; > > NOTE: DATA statement used: > > 210 > 211 %put &b; > Program 'L:\\xxx\\yyy\\zzz.sas' > > As you can see, %sysfunc version dose not work, but data _null_ version is OK. > Any idea what I did wrong in the %sysfunc version? > > Thanks, > > Ya > > > -----Original Message----- > From: Droogendyk, Harry [mailto:Harry.Droogendyk@CIBC.COM] > Sent: Friday, February 28, 2003 7:20 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: Translate double quote to single quote in a macro variable > ? > > > 171 %let a=Program "L:\xxx\yyy\zzz.sas"; > 172 %let b=%sysfunc(translate(&a,'"',"'")); > 173 %Put b = &b; > b = Program 'L:\xxx\yyy\zzz.sas' > > -----Original Message----- > From: Huang, Ya [mailto:yhuang@AMYLIN.COM] > Sent: February 28, 2003 7:13 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Translate double quote to single quote in a > macro variable ? > > Happy Friday! > > I have a macro variable (actually it is auto macro var > 'sysprocessname'), > which has value like this (when runs in batch mode): > > Program "L:\xxx\yyy\zzz.sas"; > > Since it already has double quote in its value, it can't be > used to assign a data step var simply use double quote like > a="&b", > neither can it be used in footnote, title etc., therefore, I > need to > translate the double quote to single quote. I have one way > to do it now, > but it need a data step as below. I wonder if there is a > more > elegant solution, hopefully a one liner. > > Thanks > > Ya Huang > > --------------- > > 28 %let a=Program "L:\xxx\yyy\zzz.sas"; > 29 > 30 data _null_; > 31 b=translate(symget('a'),"'",'"'); > 32 call symput('a',b); > 33 run; > > NOTE: DATA statement used: > > 34 > 35 %put &a; > Program 'L:\xxx\yyy\zzz.sas'


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