BookmarkSubscribeRSS Feed
kochsner
Calcite | Level 5

I am using if-then statements in a program I am running.  I have successfully run the program using data step processing, and am now trying an alternative method using proc iml.  However, the if-then statements are not working as they should when using IML.  I do not recieve error messages in the log, but the results are not what they should be.  Does proc iml require different language when using 'if-then' statements?  Below is the code I am referring to:

 

if 0 <= yg < 2 then YG_SCS= YG1_Avg;
if 2 <= yg < 2.5 then YG_SCS = YG2_Avg;
if 2.5 <= yg < 3 then YG_SCS = YG2A_Avg;
if 3 <= yg < 4 then YG_SCS = YG3_Avg;
if 4 <= yg < 5 then YG_SCS = YG4_Avg;
else if yg >= 5 then YG_SCS =YG5_Avg;

2 REPLIES 2
Rick_SAS
SAS Super FREQ

The DATA step supports the ternary operator that you mention. This is called the "implied AND operator."  In other languages, including SAS/IML, you need to use an explicit operator to obtain the result you want. For details, explanation, and the IML syntax, see the article

"The DATA step and the implied AND operator."

 

The article concludes:

Don't use the DATA step syntax in your SAS/IML programs. Instead, use an explicit AND operator such as (-2<x & x<2).

Rick_SAS
SAS Super FREQ

Do you have additional questions? If not, please mark this questions as solved so that others know that it has been answered.

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!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 795 views
  • 0 likes
  • 2 in conversation