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

I am new to using proc iml and have the following expression that doesn't seem to be working which I believe should be equivalent to 'if-then-else' statements in the data step. The variable 'teventBX' should be assigned a value (either period1/2/3/4/5) based on mutually exclusive conditional expressions.

 

teventBX = period1#(period1 < p1duration) + period2#((period1 > p1duration) & (1 <= period2 < 2))
+ period3#((period1 > p1duration) & (period2 > (p1duration + p2duration)) & (2 <= period3 < 3))
+ period4#((period1 > p1duration) & (period2 > (p1duration + p2duration)) & (period3 > (p1duration + p2duration + p3duration)) & (3 <= period4 < 4))
+ period5#((period1 > p1duration) & (period2 > (p1duration + p2duration)) & (period3 > (p1duration + p2duration + p3duration)) & (period4 > (p1duration + p2duration + p3duration + p4duration)) & (4 <= period5 < 5))
+ period5#((period1 > p1duration) & (period2 > (p1duration + p2duration)) & (period3 > (p1duration + p2duration + p3duration)) & (period4 > (p1duration + p2duration + p3duration + p4duration)) & (period5 > 5));

 

A few records in the dataset to help understand the issue. The last column has the correct values that should have been the result of the above code. But, except for the first 2 expressions for period1 and period2, the statement above is just adding up the period values for periods 3-5. For example, in Obs3 below, teventBX = period2 + period3 + period4 + period5. And in Obs4, teventBX = period2 + period3 + period4.

 

Obs

period1

p1duration

period2

p2duration

period3

p3duration

period4

p4duration

period5

p5duration

teventBX

Correct teventBX

1

1.7561

1

1.2074

1

5.9824

1

10.7529

1

4.6408

1

1.207

1.2074

2

0.6808

1

9.4134

1

7.1525

1

3.6021

1

4.7635

1

0.681

0.6808

3

1.7161

1

33.2933

1

42.1225

1

10.5065

1

4.1977

1

90.1200

4.1977

4

7.5841

1

16.5281

1

11.4061

1

3.8003

1

15.0174

1

31.7345

3.8003

5

10.4676

1

26.2526

1

2.0952

1

13.1565

1

4.8462

1

28.3478

2.0952

6

1.4104

1

4.0418

1

6.8128

1

9.4646

1

4.8171

1

25.1362

4.8171

7

4.2862

1

8.7941

1

2.5706

1

5.3440

1

7.3122

1

11.3647

2.5706

8

1.4407

1

2.1727

1

13.6600

1

37.2924

1

4.4550

1

57.5800

4.4550

9

7.8799

1

3.1210

1

4.2688

1

3.9127

1

11.4282

1

11.3025

3.9127

 

Any help is appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

The expressions

(1 <= period2 <= 2)

and

(2 <= period3 < 3)

are not valid IML expressions. They should be replaced by 

(1 <= period2) & (period2 <= 2)

and

(2 <= period3) & (period3 < 3)

 

To learn more about the BETWEEN operator in the DATA step and why it is not supported in MIL (or R or MATLAB....) see

https://blogs.sas.com/content/iml/2012/02/20/the-data-step-and-the-implied-and-operator.html

 

View solution in original post

2 REPLIES 2
sbxkoenk
SAS Super FREQ

Hello,

 

There's a separate board for
SAS/IML Software and Matrix Computations
Statistical programming, matrix languages, and more
(Under the "Analytics" header).

 

I have moved your question to that place.

 

BR,

Koen

Rick_SAS
SAS Super FREQ

The expressions

(1 <= period2 <= 2)

and

(2 <= period3 < 3)

are not valid IML expressions. They should be replaced by 

(1 <= period2) & (period2 <= 2)

and

(2 <= period3) & (period3 < 3)

 

To learn more about the BETWEEN operator in the DATA step and why it is not supported in MIL (or R or MATLAB....) see

https://blogs.sas.com/content/iml/2012/02/20/the-data-step-and-the-implied-and-operator.html

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 585 views
  • 1 like
  • 3 in conversation