Hi,
I am setting up a bin packing model based on the SAS example (http://support.sas.com/documentation/cdl/en/ormpug/67517/HTML/default/viewer.htm#ormpug_decomp_examp...)
The data definition step looks as follows:
data dvr;
input opponent $ size;
datalines;
Clemson 1.36
Clemson2 1.97
Duke 2.76
Duke2 2.52
FSU 2.56
FSU2 2.34
GT 1.49
[...]
;
I am new to SAS and don't really know how to access the data. In my application, I have a third value (rating) for each data row as follows:
data dvr;
input opponent $ size $ rating;
datalines;
Clemson 1.36 1
Clemson2 1.97 2
Duke 2.76 3
Duke2 2.52 3
FSU 2.56 2
FSU2 2.34 1
GT 1.49 2
[...]
I thought that I can call these values like using an array but it does not work.
I would like to set up a constraint that compares the third value to another value and sets up a constraint.
If anybody could help me and give a hint on how I can access or loop though these values, it would be amazing!
The "size" column is numeric, so omit the $ in the DATA step INPUT statement:
input opponent $ size rating;
The following PROC OPTMODEL statements show how to modify the documentation example to read the additional "rating" column:
set <str> PRODUCTS;
num size {PRODUCTS};
num rating {PRODUCTS};
read data dvr into PRODUCTS=[opponent] size rating;
The "size" column is numeric, so omit the $ in the DATA step INPUT statement:
input opponent $ size rating;
The following PROC OPTMODEL statements show how to modify the documentation example to read the additional "rating" column:
set <str> PRODUCTS;
num size {PRODUCTS};
num rating {PRODUCTS};
read data dvr into PRODUCTS=[opponent] size rating;
put rating['FSU'];
Thank you for your quick reply Rob!
This works fine and I noticed, I should have asked the question differently... Is it possible to iterate through these parameters (in array shape)?
For example:
for all i in rows:
for all j in columns:
put arrayelement[i,j]
Thank you in advance, Hendrik
Yes, you can explicitly loop through the index sets of these one-dimensional arrays:
for {i in OPPONENTS} put size[i] rating[i];
Or implicitly loop:
put size[*] rating[*];
Or include an equals sign to also display the names:
for {i in OPPONENTS} put size[i]= rating[i]=;
put size[*]= rating[*]=;
Or just print:
print size rating;
Thank you Rob!
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.
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.