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!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.