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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

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;

View solution in original post

6 REPLIES 6
RobPratt
SAS Super FREQ

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;
Hendrik
Calcite | Level 5
Thank you for your answer Rob! Based on this, how do I access the parameter?
For example, if I would like to print the rating of FSU, is there a way to say 'put PRODUCTS[5,3]?
Hendrik
Calcite | Level 5

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

RobPratt
SAS Super FREQ

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;

 

SAS Innovate 2025: Register Now

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!

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
  • 6 replies
  • 1362 views
  • 0 likes
  • 2 in conversation