BookmarkSubscribeRSS Feed
LouiseS
Calcite | Level 5

Hey,

 

I have a syntaxe problem with the following procedure, someone can help me? I think that it is with the objectif function.

 

Thank you,

 

 

 

data fooddata; infile datalines;
input name $ prod $ cost prot fat carb cal Moy; datalines;
Breadb B 2.5 4 1 15 90 150
Breadc C 2 4 1 15 90 212
Milkb B 4 8 5 11.7 120 0
Milkc C 3.5 8 5 11.7 120 350
Cheeseb B 12 7 9 0.4 106 20
Cheesec C 8 7 9 0.4 106 50

;
run;

proc optmodel; /* declare index set */ set<str> FOOD;
/* declare variables */ var diet{FOOD} >= 0;
/* objective function */
num Moy{FOOD}; num cost{FOOD}; min f=(sum{i in FOOD, j=2i-1}((Moy[j]+Moy[j+1])-(diet[j]+diet[j+1]))**2)+sum{i in FOOD}cost[i]*diet[i];

/* constraints */
num prot{FOOD}; num fat{FOOD}; num carb{FOOD}; num cal{FOOD};
num min_cal, max_prot, min_carb, min_fat; con cal_con: sum{i in FOOD}cal[i]*diet[i] >= 300;
con prot_con: sum{i in FOOD}prot[i]*diet[i] <= 10; con carb_con: sum{i in FOOD}carb[i]*diet[i] >= 10;
con fat_con: sum{i in FOOD}fat[i]*diet[i] >= 8;

/* read parameters */ read data fooddata into FOOD=[name] cost prot fat carb cal Moy;

/* solve and print the optimal solution */ solve with lp/logfreq=1; /* print each iteration to log */ print diet;
quit;

2 REPLIES 2
mkeintz
PROC Star

Please show the log for this program.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
LouiseS
Calcite | Level 5

Thank you.

I found another way to make it work.

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 640 views
  • 0 likes
  • 2 in conversation