BookmarkSubscribeRSS Feed
hzk0065
Calcite | Level 5

my code is not working. It is showing an error of unknown c1, c2, c3, c4, and so unknown f. Please help me out. Thanks

data x (drop = i);
do i = 1 to 100;
c1 = ranuni(i);
c2 = ranuni(i);
c3 = ranuni(i);
c4 = ranuni(i);
output;
end;
run;

proc print data = x;var c1 c2 c3 c4;run;

proc optmodel;
var a;
var b;
%do i = 1 %to dim(x)
minimize f =(((1-((c1[i]*a+c2[i]*b)/30.9))**2)*1.08)+(((1-((c3[i]*a+c4[i]*b)/12.8))**2)*1);
con P: a+b=1.0;
con Q: a >= 0.0;
con R: b >= 0.0;
con T: a <= 1.0;
con U: b <=1.0;
solve with qp;

/* print the optimal solution */
print a b;
print f;
quit;
end;


var b;
%do i = 1 %to dim(x)
minimize f =(((1-((c1[i]*a+c2[i]*b)/30.9))**2)*1.08)+(((1-((c3[i]*a+c4[i]*b)/12.8))**2)*1);
con P: a+b=1.0;
con Q: a >= 0.0;
con R: b >= 0.0;
con T: a <= 1.0;
con U: b <=1.0;
solve with qp;

/* print the optimal solution */
print a b;
print f;
quit;
end;

3 REPLIES 3
Rick_SAS
SAS Super FREQ

The syntax you've written is not valid for several reasons, all having to do with the macro processing.

  1. The %DO macro loop is missing a semicolon
  2. The END statement should presumably be %END?
  3. You can't use a %DO macro loop in open code. It has to be part of a function-style macro (%MACRO/%MEND)

Please describe in words what you are trying to accomplish so we can advise the best way to do it.

 

hzk0065
Calcite | Level 5
Thanks for reply,
I am trying to write a minimize function for a and b using any random values of c1-c4 between 1 to 100. In the minimize function, corresponding values of the same row for all c1-c4 will go as input and it will repeat for all 100 rows. The value of a and b supposed to be close to 1 and 0 respectively. I hope it is clear now? Please let me know if you have any questions?
Thanks
RobPratt
SAS Super FREQ
It sounds like you want to mimic this SAS Usage Note: http://support.sas.com/kb/42/332.html

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Discussion stats
  • 3 replies
  • 1141 views
  • 0 likes
  • 3 in conversation