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-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!

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
  • 3 replies
  • 661 views
  • 0 likes
  • 3 in conversation