Hello guys,
What i want to do here is to soustract a value to my all tables. What i don't understand is that when i'm doing step by step it's working. like wha't follow :
data wilco;
set test;
var1=var1-varvec;
var2=var2-varvec;
run;but i want to do it for 128 variable so you can understand that i don't want to write all the unnecessary line. I tried something like that :
data wilco;
set test;
do i= 1 to 128;
var&i.= var&i.-varvec;
end;
run;But in fact it's ignoring my loop part and just do the set part. i'm surely missing something there, and if you could help me to find it !
Thanks.
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
32768 at 85:17
NOTE: There were 256 observations read from the data set WORK.TEST.
NOTE: The data set WORK.WILCO has 256 observations and 131 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
Hi @boubou31
In your example, "i" is not a macrovariable so you can't refer to it as &i.
What you need is an array, to reference a group of columns of the same type.
in the below code, var1 is equivalent to var(1), as this variable is in position 1 in the array.
Best,
data wilco;
set test;
array var(128); /* the array 'var' references a group of columns: var1, var2, ... until var 128*/
do i= 1 to dim(array); /* the array dimension is 128 = the DIM(function) */
var(i)= var(i)-varvec;
end;
run;
Best,
Hi @boubou31
In your example, "i" is not a macrovariable so you can't refer to it as &i.
What you need is an array, to reference a group of columns of the same type.
in the below code, var1 is equivalent to var(1), as this variable is in position 1 in the array.
Best,
data wilco;
set test;
array var(128); /* the array 'var' references a group of columns: var1, var2, ... until var 128*/
do i= 1 to dim(array); /* the array dimension is 128 = the DIM(function) */
var(i)= var(i)-varvec;
end;
run;
Best,
Thanks ! but i'm wondering usually i'm using "i" as a macrovariable when it isn't in a data set and that's working. So it's cause is inside a data set that i cannot use this writing : "&i" ?
Hi @boubou31
You can refer to &i as a macrovariable if you use iterative DO statements inside a macro:
%do i=1 %to 128;
... -> using &i.
%end;
Best,
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.