BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I am using SELECT and WHEN to check values in a loop.

I am having a problem with the following code -

do i=1 to 5;

if Rate(i)=0 then
UnmeasVol(i) = 0;
else
select (i);
when (4)
if ExSuccVol + ExUnsuccVol + NewSuccVol + NewUnsuccVol = 0 then UnmeasVol(4) = 0;
else
UnmeasVol (4) = TotMeasWld / (ExSuccVol + ExUnsuccVol + NewSuccVol+ NewUnsuccVol) * (ExBookedConv + NewBookedConv)*Rate(i);
when (5)
UnmeasVol(5) = Ex_Reg_Meas_Workload.SL_NAO_WLD + New_Reg_Meas_Workload.SL_NAO_WLD;
Otherwise
UnmeasVol(i)=TotMeasRegWld * Rate(i);
end;
end;

It seems to fall down when trying to execute the code after When (4) (i=4) and is expecting WHEN, OTHERWISE or END.

Not sure why.........any ides????
3 REPLIES 3
GertNissen
Barite | Level 11
Your syntax is wrong - try one of the 2 altenatives (must be modified for your need)
1)[pre]
do i=1 to 5;
if Rate(i)=0 then
UnmeasVol(i) = 0;
else
select (i);
when (4)
UnmeasVol(4) = TotMeasWld / (ExSuccVol + ExUnsuccVol + NewSuccVol+ NewUnsuccVol) * (ExBookedConv + NewBookedConv)*Rate(i);
when (5)
UnmeasVol(5) = Ex_Reg_Meas_Workload.SL_NAO_WLD + New_Reg_Meas_Workload.SL_NAO_WLD;
Otherwise
UnmeasVol(i)=TotMeasRegWld * Rate(i);
end;
if ExSuccVol + ExUnsuccVol + NewSuccVol + NewUnsuccVol = 0 then UnmeasVol(4) = 0;
end;
[/pre]
2)[pre]
do i=1 to 5;
if Rate(i)=0 then
UnmeasVol(i) = 0;
else
select (i);
when (4)
do;
if ExSuccVol + ExUnsuccVol + NewSuccVol + NewUnsuccVol = 0 then UnmeasVol(4) = 0;
else
UnmeasVol (4) = TotMeasWld / (ExSuccVol + ExUnsuccVol + NewSuccVol+ NewUnsuccVol) * (ExBookedConv + NewBookedConv)*Rate(i);
end;
when (5)
UnmeasVol(5) = Ex_Reg_Meas_Workload.SL_NAO_WLD + New_Reg_Meas_Workload.SL_NAO_WLD;
Otherwise
UnmeasVol(i)=TotMeasRegWld * Rate(i);
end;
end;
[/pre]
More info at http://support.sas.com/onlinedoc/913/getDoc/da/lrdict.hlp/a000201966.htm
deleted_user
Not applicable
Ok, that makes sense, but it does seem strange that you can't perform an IF statement within a SELECT WHEN statement?

Is there any other way of performing such a function within a SELECT WHEN statement as I can forsee me having problems in future if I can't do this?


Thanks for the code though 🐵
GertNissen
Barite | Level 11
You can use IF within as SELECT statement - Look at http://support.sas.com/onlinedoc/913/getDoc/da/lrdict.hlp/a000201966.htm#a000202177 or my example 2) above.

Your problem is not the IF statement, but the fact that your are using more than 1 line of code within the WHEN statement. You must use DO/END structure, to write more statements i.e. IF/THEN/ELSE.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 597 views
  • 0 likes
  • 2 in conversation