BookmarkSubscribeRSS Feed
BjarneGjerde
Calcite | Level 5

How to get these example data from e.g. an Excel file (or ascii file):  

 

Var c1 c2

A     2    5

B     4    3

C     6    7

 

Into the vectors c1 and c2 in the below program.

Proc optmodel;

set box={"A","B","C"};

var Q{i in box} >=0;

 

number c1{i in box}=[2 4 6];

number c2{i in box}=[5 3 7];

 

etc. 

 

quit;

4 REPLIES 4
RobPratt
SAS Super FREQ

First convert to a SAS data set, say indata, by using PROC IMPORT or a DATA _null_ step.  Then use the READ DATA statement:

Proc optmodel;
   set <str> box;
   var Q{box} >=0;
   number c1{box};
   number c2{box};
   read data indata into box=[Var] c1 c2;
   print c1 c2;
quit;

PROC OPTMODEL questions will get more immediate response in the Mathematical Optimization, Discrete-Event Simulation, and OR community.

BjarneGjerde
Calcite | Level 5

Thanks a lot!

But I do  not see how to get each line or Product (Var A, B, C) – into e.g. c1 {i in box}.  

 

Proc optmodel;

set box={"A","B","C"};

var Q{i in box} >=0;

number c1{i in box}=[2 4 6];

number c2{i in box}=[5 3 7];

RobPratt
SAS Super FREQ

The READ DATA statement populates box, c1, and c2 for you.  That way, you can solve a different instance of the same problem just by changing data sets without having to change your PROC OPTMODEL code.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 827 views
  • 0 likes
  • 3 in conversation