简体   繁体   中英

How to assign output from SOLVE function in PROC FCMP (SAS) to global variable/table?

I'm trying to use PROC FCMP with the function SOLVE to solve non-linear equations and insert solutions into the table automatically. For instance

proc fcmp;
      /* define the function */
   function inversesqrt(x);
      return(1/sqrt(x));
   endsub;

   y = 20;
   x = solve("inversesqrt", {.}, y, .);
   put x;
run;

After running above code x will be shown in results but i cannot utilize it in further code. I tried to save x as macro variable or as table but nothing works for me. Can somebody help me, please?

Create a second fcmp function to return the solve.

options cmplib=work.funcs;

proc fcmp outlib=work.funcs.sandbox;
      /* define the function */
   function InverseSqrt(x);
      return(1/sqrt(x));
   endsub;

   function SolveInverseSqrt(arg);
     return (solve('InverseSqrt', {.}, arg, .));
   endsub;
run;

%let x = %sysfunc(SolveInverseSqrt(20));
%put &=x;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM