BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Satori
Obsidian | Level 7

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
MarkusWeick
Barite | Level 11

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

Please keep the community friendly.
Like posts you agree with or like. Mark helpful answers as “accepted solutions”. Generally have a look at https://communities.sas.com/t5/Getting-Started/tkb-p/community_articles

View solution in original post

2 REPLIES 2
MarkusWeick
Barite | Level 11

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

Please keep the community friendly.
Like posts you agree with or like. Mark helpful answers as “accepted solutions”. Generally have a look at https://communities.sas.com/t5/Getting-Started/tkb-p/community_articles
Kurt_Bremser
Super User

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;

sas-innovate-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 234 views
  • 1 like
  • 3 in conversation