my code (that works):
data home.test2; set bv18u; array values (*) COGS--EBITDA; do i = 1 to dim(values);
if nmonths=1 then values(i) = 12/1*values(i); else if Number_of_months=2 then values(i) = 12/2*values(i);
else if nmonths=3 then values(i) = 12/3*values(i); else if nmonths=4 then values(i) = 12/4*values(i);
else if nmonths=5 then values(i) = 12/5*values(i); else if nmonths=6 then values(i) = 12/6*values(i);
else if nmonths=7 then values(i) = 12/7*values(i); else if nmonths=8 then values(i) = 12/8*values(i);
else if nmonths=9 then values(i) = 12/9*values(i); else if nmonths=10 then values(i) = 12/10*values(i);
else if nmonths=11 then values(i) = 12/11*values(i); else if nmonths=12 then values(i) = 12/12*values(i);
else if nmonths=13 then values(i) = 12/13*values(i); else if nmonths=14 then values(i) = 12/14*values(i);
else if nmonths=15 then values(i) = 12/15*values(i); else if nmonths=16 then values(i) = 12/16*values(i);
else if nmonths=17 then values(i) = 12/17*values(i); else if nmonths=18 then values(i) = 12/18*values(i);
else if nmonths=19 then values(i) = 12/19*values(i); else if nmonths=20 then values(i) = 12/20*values(i);
else if nmonths=21 then values(i) = 12/21*values(i); else if nmonths=22 then values(i) = 12/22*values(i);
else if nmonths=23 then values(i) = 12/23*values(i); else if nmonths=24 then values(i) = 12/24*values(i);
end;
to simplify this code I tried doing (that doesn't work):
data home.test1; set bv18u; array values (*) COGS--EBITDA; do i = 1 to dim(values);
do j=1 to 24; if nmonths=j then 12/j*values(i); end; end;
and I got an error. log:
733 data bvd.test1; set bv18u; array values (*) COGS--EBITDA; do i = 1 to dim(values);
734 do j=1 to 24; if nmonths=j then 12/j*values(i); end; end;
__
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
Hi @Satori,
12/j*values(i)
is not a complete statement. You will need something like
x=12/j*values(i)
or in your case
values(i)=12/j*values(i)
(I just looked at the one syntax part)
Best Markus
Hi @Satori,
12/j*values(i)
is not a complete statement. You will need something like
x=12/j*values(i)
or in your case
values(i)=12/j*values(i)
(I just looked at the one syntax part)
Best Markus
You need a complete assignment statement, and can omit the DO:
data home.test1;
set bv18u;
array values (*) COGS--EBITDA;
do i = 1 to dim(values);
if 1 le nmonths le 24 then values{i} = 12 / nmonths * values{i};
end;
run;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.