Macro returning a value

后端 未结 3 594
清酒与你
清酒与你 2021-02-13 19:56

I created the following macro. Proc power returns table pw_cout containing column Power. The data _null_ step assigns the val

3条回答
  •  自闭症患者
    2021-02-13 20:11

    You can't do what you're trying to do this way. Macros in SAS are a little different than in a typical programming language: they aren't subroutines that you can call, but rather just code that generate other SAS code that gets executed. Since you can't run proc power inside of a data step, you can't run this macro from a data step either. (Just imagine copying all the code inside the macro into the data step -- it wouldn't work. That's what a macro in SAS does.)

    One way to do what you want would be to read each observation from tmp one at a time, and then run proc power. I would do something like this:

    /* First count the observations */
    data _null_;
      call symputx('nobs',obs);
      stop;
      set tmp nobs=obs;
    run;
    
    /* Now read them one at a time in a macro and call proc power */
    %macro power;
      %do j=1 %to &nobs;
        data _null_;
           nrec = &j;
           set tmp point=nrec;
           call symputx('meanA',meanA);
           call symputx('stdA',stdA);
           call symputx('nA',nA);
           call symputx('meanB',meanB);
           call symputx('stdB',stdB);
           call symputx('nB',nB);
           stop;
        run;
    
       proc power; 
         twosamplemeans test=diff_satt 
         groupmeans = &meanA | &meanB 
         groupstddevs = &stdA | &stdB
         groupns = (&nA &nB)
         power = .;    
        ods output Output=pw_out;
      run;
    
      proc append base=pw_out_all data=pw_out; run;
     %end;
    %mend;
    
    %power;
    

    By using proc append you can store the results of each round of output.

    I haven't checked this code so it might have a bug, but this approach will work.

提交回复
热议问题