From: avi on 25 Dec 2007 16:35 Hello, I have a macro variable &mmm that resolves to "3" (not 3!) I want to make a comparison of the form: %eval(&mmm<2) I got TRUE mmm is interpreted as string How do I cause the comparison to interpret &mmm as 3 and not as "3"? Or, how do I cause &mmm to resolve to 3 (and not "3")? I have used the many dequoting functions but whithout success so far Thanks a lot Avi
From: "Howard Schreier <hs AT dc-sug DOT org>" on 25 Dec 2007 16:44 On Tue, 25 Dec 2007 13:35:20 -0800, avi <aviben(a)BEZEQINT.NET.IL> wrote: >Hello, > >I have a macro variable &mmm that resolves to "3" (not 3!) > >I want to make a comparison of the form: > >%eval(&mmm<2) > >I got TRUE mmm is interpreted as string > >How do I cause the comparison to interpret &mmm as 3 and not as "3"? > >Or, how do I cause &mmm to resolve to 3 (and not "3")? Hard to say without seeing the code which creates &MMM. > >I have used the many dequoting functions but whithout success so far > >Thanks a lot >Avi
From: avi on 25 Dec 2007 17:16 The code is a macro that computes the number of observations in a dataset %macro numobs(dsn); %global mmm; data _null_; if 0 then set &dsn nobs=nobs; call symput('mmm',trim(left(put(nobs,8.)))); stop; run; %mend numobs; Thanks Avi
From: Ian Whitlock on 25 Dec 2007 17:40 Summary: Quote marks are for generated SAS code. #iw-value=1 Avi, Simplest solution is to avoid quote marks in the first place. However, here are 3 solutions when you already have them. %let mmm = "3" ; %put mmm = >>>&mmm<<< ; %put %eval(&mmm<2) ; /* assuming single digit with surrounding quote marks */ %put >>>%substr(&mmm,2,1)<<< ; %put %eval(%substr(&mmm,2,1)<2) ; /* assuming surrounding quote marks */ %put >>>%sysfunc(translate(&mmm,%str( ),%str(%"%')))<<< ; %put %eval(%sysfunc(translate(&mmm,%str( ),%str(%"%')))<2) ; %let q = %qsubstr(&mmm,2) ; %let q = %substr(&q,1,%length(&q)-1) ; %put >>>&q<<< ; %put %eval(&q<2) ; Ian whitlock ================= Date: Tue, 25 Dec 2007 13:35:20 -0800 Reply-To: avi <aviben(a)BEZEQINT.NET.IL> Sender: "SAS(r) Discussion" From: avi <aviben(a)BEZEQINT.NET.IL> Organization: http://groups.google.com Subject: Macro variable comparison Comments: To: sas-l Content-Type: text/plain; charset=ISO-8859-1 Hello, I have a macro variable &mmm that resolves to "3" (not 3!) I want to make a comparison of the form: %eval(&mmm<2) I got TRUE mmm is interpreted as string How do I cause the comparison to interpret &mmm as 3 and not as "3"? Or, how do I cause &mmm to resolve to 3 (and not "3")? I have used the many dequoting functions but whithout success so far Thanks a lot Avi
From: shiling99 on 25 Dec 2007 18:22
On Dec 25, 5:16 pm, avi <avi...(a)bezeqint.net.il> wrote: > The code is a macro that computes the number of observations in a > dataset > > %macro numobs(dsn); > %global mmm; > data _null_; > if 0 then set &dsn nobs=nobs; > call symput('mmm',trim(left(put(nobs,8.)))); > stop; > run; > %mend numobs; > > Thanks > Avi Based on your codes, I cannot find anything wrong. See the log below. 114 data t1; 115 x=1;output;output;output; 116 run; NOTE: The data set WORK.T1 has 3 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 117 118 %macro numobs(dsn); 119 %global mmm; 120 data _null_; 121 if 0 then set &dsn nobs=nobs; 122 call symput('mmm',trim(left(put(nobs,8.)))); 123 stop; 124 run; 125 %mend numobs; 126 127 %numobs(dsn=t1) NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds 128 %put >>&MMM<<; >>3<< 129 130 %put >>>1). %eval(&mmm < 2)<<<; >>>1). 0<<< 131 %put >>>2). %eval(&mmm > 2)<<<; >>>2). 1<<< |