|
|
The %TO value of the %DO I loop is invalid
Hi I have the following test code below. The calls to %add and %leng
marcos work fine but %addwrong gives me an errors that I don't
understand how to resolve, any help appreciated:
/*****************************************************/
%macro add (marr, val);
sum=0;
%do i=1 %to &val;
sum= &marr(&i) + sum;
%end;
put sum;
%mend add;
%macro leng(marr);
len=dim(&marr);
put len;
%mend leng;
%macro addwrong (marr);
sum=0;
val = dim(&marr);
%do i=1 %to &val;
sum= &marr(&i) + sum;
%end;
put sum;
%mend addwrong;
data _null_;
array arr(7) _temporary_ (1.7 2.7 3 4 7 4 23.8);
%add(arr,7);
run;
data _null_;
array arr(7) _temporary_ (1.7 2.7 3 4 7 4 23.8);
%leng(arr);
run;
data _null_;
array arr(7) _temporary_ (1.7 2.7 3 4 7 4 23.8);
%addwrong(arr);
run;
/******************************************************/
The last call gives this error:
ERROR: A character operand was found in the %EVAL function or %IF
condition where a numeric operand is required. The condition was: &val
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: The macro ADDWRONG will stop executing.
|
|
0
|
|
|
|
Reply
|
franco734 (14)
|
3/20/2011 11:57:05 AM |
|
On Mar 20, 4:57=A0am, francogrex <fra...@grexdot.org> wrote:
> Hi I have the following test code below. The calls to %add and %leng
> marcos work fine but %addwrong gives me an errors that I don't
> understand how to resolve, any help appreciated:
> /*****************************************************/
> %macro add (marr, val);
> =A0 =A0 sum=3D0;
> =A0 =A0 %do i=3D1 %to &val;
> =A0 =A0 =A0 =A0 sum=3D &marr(&i) + sum;
> =A0 =A0 =A0 =A0 %end;
> =A0 =A0 put sum;
> =A0 =A0 %mend add;
>
> %macro leng(marr);
> =A0 =A0 len=3Ddim(&marr);
> =A0 =A0 put len;
> =A0 =A0 %mend leng;
>
> %macro addwrong (marr);
> =A0 =A0 sum=3D0;
> =A0 =A0 val =3D dim(&marr);
> =A0 =A0 %do i=3D1 %to &val;
> =A0 =A0 =A0 =A0 sum=3D &marr(&i) + sum;
> =A0 =A0 =A0 =A0 %end;
> =A0 =A0 put sum;
> =A0 =A0 %mend addwrong;
>
> data _null_;
> =A0 =A0 array arr(7) _temporary_ (1.7 2.7 3 4 7 4 23.8);
> =A0 =A0 %add(arr,7);
> run;
>
> data _null_;
> =A0 =A0 array arr(7) _temporary_ (1.7 2.7 3 4 7 4 23.8);
> =A0 =A0 %leng(arr);
> run;
>
> data _null_;
> =A0 =A0 array arr(7) _temporary_ (1.7 2.7 3 4 7 4 23.8);
> =A0 =A0 %addwrong(arr);
> run;
> /******************************************************/
> The last call gives this error:
> ERROR: A character operand was found in the %EVAL function or %IF
> condition where a numeric operand is required. The condition was: &val
> ERROR: The %TO value of the %DO I loop is invalid.
> ERROR: The macro ADDWRONG will stop executing.
val isn't a macro variable in that macro.
|
|
0
|
|
|
|
Reply
|
Reeza
|
3/20/2011 5:48:27 PM
|
|
But in general how to you deal with this. Suppose I have a macro:
%macro test (arg=);
array arrayone [&arg]; /* This is ok */
array arraytwo [&arg+1] /* This is not ok */
....
How do we manage these situation when I want %test(3) and then the
arraytwo needs to take dimension 4... ?
|
|
0
|
|
|
|
Reply
|
Francogrex
|
3/24/2011 8:15:36 PM
|
|
you cannot use datastep variable in macro code. val is not a macro
variable, so macro interpreter knows nothing about it.
try to do
%let val =3D %sysfunc(dim(&marr));
instead of
val =3D dim(&marr);
%sysfunc lets you call standard SAS functions and return their results
to _macro_ variables.
On Mar 24, 4:15=A0pm, Francogrex <fra...@grex.org> wrote:
> But in general how to you deal with this. Suppose I have a macro:
> %macro test (arg=3D);
> array arrayone [&arg]; =A0 /* This is ok */
> array arraytwo [&arg+1] /* This is not ok */
> ...
> How do we manage these situation when I want %test(3) and then the
> arraytwo needs to take dimension 4... ?
|
|
0
|
|
|
|
Reply
|
m1st
|
3/25/2011 9:05:55 AM
|
|
|
3 Replies
455 Views
(page loaded in 0.086 seconds)
Similiar Articles: Loop to evaluate consecutive values in array - comp.soft-sys ...Eval in gawk - comp.lang.awk But you can store values in a shared array instead of in individual ... The %TO value of the %DO I loop is invalid ... database sort/validate ... Text line contains an invalid character - comp.text.tex... an invalid character l.1 I can't seem to get out of this loop ... Text line contains an invalid character - comp.text.tex I do pdflatex of my document and sometimes it ... Assignin into Matlab variable struct - comp.soft-sys.matlab ...I would like to do such thing : [code] PARAMS ... the variable that would be changed into > the loop as a first field in the PARAMS cell array.The different values ... password expiration check script - comp.unix.solarisI'm looking for a script I can run in a for loop to a crapload of sun/linux/hp ... of max for $name" max=-1 fi if [ "$lastchg" = "" ]; then echo "invalid value of ... collecting data in loops - comp.soft-sys.matlabHow do I store results generated in a loop when they are of different lengths? for i=1:390 find(mat(:,4)==i); end; I'm searching a matrix for values in the ... gluProject - z value - comp.graphics.api.openglHi, how can I get the z-value depending on my znear ... my forename from: tonreG.Frisch.at.Dream-D-Sign.de@invalid ... you'd assign the zi value to intensity, then just loop ... Iterating over a String - comp.lang.java.help-- Eric Sosman esosman@ieee-dot-org.invalid ... if that is what you want to do. I use the for loop ... ode45 and in iteration of the loop ... matrix conataining all values ... Do Loop Shift Column - comp.soft-sys.sasDo Loop Shift Column - comp.soft-sys.sas select specified columns in ch. array ... function in a loop startin with first column ... for example, when the values in a column do ... Plotting multiple variables generated from a loop in the same ...The amount of TLs generated depends on how the loop is set...so i may vary from 3~30 different sets of value I tried to do something like this: for m=1:length(x ... Please help, how to use "for loop" to list out the coordinate ...Now i'm assigned to use >>for loop / for function>for ... number (For example, [t,10]=max(z);), it showed "Invalid ... is an output, hence you don't assign it a value, the ... invalid input - Java - Forums at ProgrammersHeaven.comRe: invalid input Posted by wills2365 on 23 Feb 2007 at 10:34 AM ... false; // Assume an error : : while (!isInteger) { // loop while the entered value is not an ... Run-time Error 380 Invalid Property Value With ListBox For LoopLoop Threw Listbox Items One At A Time hey, I am trying to take listbox items which are added dynamically by the user and I would like to be able to click a button ... 7/24/2012 12:11:11 PM
|
|
|
|
|
|
|
|
|