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

Is there any way we can change length of the variable created with CREATE DATA statement? I have a text variable which is used as a key variable in PROC OPTMODEL but it gets truncated in the data which is created with CREATE DATA statement. I am new to PROC OPTMODEL. Could you also please give a example of how OR condition is used in constraint? For example, sum {c in customers} (product[c] IN ('A', 'B'))

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

The CREATE DATA statement has a LENGTH= option:

http://go.documentation.sas.com/#!/?docsetId=ormpug&docsetVersion=14.2&docsetTarget=ormpug_optmodel_...

 

Correct syntax for your sum is:

sum {c in customers: product[c] IN {'A', 'B'}}

For new users of PROC OPTMODEL, I recommend this book of examples.

View solution in original post

5 REPLIES 5
RobPratt
SAS Super FREQ

The CREATE DATA statement has a LENGTH= option:

http://go.documentation.sas.com/#!/?docsetId=ormpug&docsetVersion=14.2&docsetTarget=ormpug_optmodel_...

 

Correct syntax for your sum is:

sum {c in customers: product[c] IN {'A', 'B'}}

For new users of PROC OPTMODEL, I recommend this book of examples.

Ujjawal
Quartz | Level 8

Thanks @RobPratt for your reply. Very much appreciated!

Is sum {c in customers: product[c] IN {'A', 'B'}} equivalent to  sum {c in customers} (product[c] IN {'A', 'B'})? I get confused with ':' symbol. Does it represent AND condition? Many times i see ':' is not required to apply AND condition.

RobPratt
SAS Super FREQ

The colon : operator (which you can think of as "such that") allows you to select a subset based on a logical expression:

http://go.documentation.sas.com/#!/?docsetId=ormpug&docsetVersion=14.2&docsetTarget=ormpug_optmodel_...

 

The following expressions are all equivalent and count the number of customers whose product is A or B:

sum {c in customers} (product[c] IN {'A', 'B'})
sum {c in customers} (if product[c] IN {'A', 'B'} then 1 else 0)
sum {c in customers} (if product[c] IN {'A', 'B'} then 1)
sum {c in customers: product[c] IN {'A', 'B'}} 1
card({c in customers: product[c] IN {'A', 'B'})

See also my reply here, which is similar:

https://communities.sas.com/t5/Mathematical-Optimization/Optimize-Traveling-Distance/td-p/308817/pag...

 

Ujjawal
Quartz | Level 8

Thanks @RobPratt. You have been very helpful. I've made a good progress in learning PROC OPTMODEL and credit goes to you for providing links and clarifying doubts with examples.

 

Last question - Why do we need to write 1 in the following statement?

 

sum {c in customers: product[c] IN {'A', 'B'}} 1

Can't we simple write (without 1) -

 

sum {c in customers: product[c] IN {'A', 'B'}}

I remember you provided the similar solution wherein you mentioned 1 before dividing by 3-

ceil(sum {c in customers: sales[c] > 50} 1 / 3)

 

 

RobPratt
SAS Super FREQ
Glad to help. The 1 is there because the SUM operator requires a summand.

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.

Discussion stats
  • 5 replies
  • 969 views
  • 1 like
  • 2 in conversation