0
votes

I've googled lots papers on the subject but don't seem to find what I want. I'm a beginner at SAS Macro, hoping to get some help here. Here is what I want:

I have a dataset with 1200 variables. I want a macro to run those 1199 variables as OUTCOME, and store the P-values of logistic regression in a dataset. Also the dependent variable "gender" is character, and so are the outcome variables. But I don't know how to put class statement in the macro. Here is an example of how I run it as a single procedure.

 proc logistic data=Baseline_gender ;
 class gender(ref="Male") / param=ref;
 model N284(event='1')=gender ; 
 ods output ParameterEstimates=ok;
 run;

My idea was to create ODS output and delete the unnecessary variables other than the P-value and merge them into one dataset according to the OUTCOME variable names in the model: e.g.

 Variable P-value
 A1       0.005
 A2       0.018
 ..       ....

I tried to play with some proc macro but I just cant get it work!!! I really need help on this, Thank you very much.

3
You might want to take a look at this example. By using the options selection=forward maxstep=1 details on the model statement you can get an ODS output table (EffectNotInModel) comparing the chi-squared tests for each of the individual variables. You can then pass all your variables in one model statement using variable lists.SRSwift
I'm aware of the variable list, but I just dont know how to apply it to outcome, with reference group. I don't know the syntax and such. I've read some articles and macros but they are written without "class" and reference specification. And they are all about models with the same OUTCOME but many predictors. But in my case I wanna use one predictor against a list of oucome.user4585472
my apologies, I had misunderstood your problem. I've presented an alternative macro free approach below.SRSwift

3 Answers

0
votes

SRSwift might be onto something (don't know enough about his method to tell), but here's a way to do it using a macro.

First, count the number of variables in your dataset. Do this by selecting your table from the dictionary.columns table. This puts the number of variables into &sqlobs. Now read the variable names from the dictionary table into macro variables var1-var&sqlobs.

%macro logitall;
proc sql;
create table count as
select name from dictionary.columns
where upcase(libname) = 'WORK'
  and upcase(memname) = 'BASELINE_GENDER'
  and upcase(name) ne 'GENDER'
;

select name into :var1 - :var&sqlobs
from dictionary.columns
where upcase(libname) = 'WORK'
  and upcase(memname) = 'BASELINE_GENDER'
  and upcase(name) ne 'GENDER'
;
quit;

Then run proc logistic for each dependent variable, each time outputting a dataset named after dependent variable.;

%do I = 1 %to &sqlobs;
  proc logistic data=Baseline_gender ;
    class gender(ref="Male") / param=ref;
    model &&var&I.(event='1')=gender ; 
    ods output ParameterEstimates=&&var&I.;
  run;
%end;

Now put all the output datasets together, creating a new variable with the dataset name using indsname= in the set statement.

data allvars;
  format indsname dsname varname $25.; 
  set
  %do I = 1 %to &sqlobs;
    &&var&I.
  %end;
  indsname=dsname;
  varname=dsname;
  keep varname ProbChiSq;
  where variable ne 'Intercept';
run;
%mend logitall;

%logitall;
0
votes

Here is a macro free approach. It restructures the data in advance and uses SAS's by grouping. The data is stored in a deep format where the all the outcome variable values are stored in one new variable.

Create some sample data:

data have;
   input 
        outcome1 
        outcome2 
        outcome3 
        gender $;
   datalines;
1 1 1 Male
0 1 1 Male
1 0 1 Female
0 1 0 Male
1 1 0 Female
0 0 0 Female
;
run;

Next transpose the data into a deep format using an array:

data trans;
    set have;
    /* Create an array of all the outcome variables */
    array o{*} outcome:;
    /* Loop over the outcome variables */
    do i = 1 to dim(o);
        /* Store the variable name for grouping */
        _NAME_ = vname(o[i]);
        /* Store the outcome value in the  */
        outcome = o[i];
        output;
    end;
    keep _NAME_ outcome gender;
run;
proc sort data = trans;
    by _NAME_;
run;

Reusing your logistic procedure but with an additional by statement:

proc logistic data = trans;
    /* Use the grouping variable to select multiple analyses  */
    by _NAME_;
    class gender(ref = "Male");
    /* Use the new variable for the dependant variable */
    model outcome = gender / noint; 
    ods output ParameterEstimates = ok;
run;
0
votes

Here is another way to do it using macro. First define all the variables to be used as outcome in a global variable and then write the macro script.

%let var = var1 var2 var3 ..... var1199;

%macro log_regression;
  %do i=1 %to %eval(%sysfunc(countc(&var., " "))+1);
    %let outcome_var = %scan(&var, &i);
    %put &outcome_var.;

    proc logistic data = baseline_gender desc;
    class gender (ref = "Male") / param = ref;
    model &outcome_var. = gender;
    ods output ParameterEstimates = ParEst_&outcome_var.;
    run;

    %if %sysfunc(exist(univar_result)) %then %do;
      data univar_result;
      set univar_result ParEst_&outcome_var.;
      run;
    %end;
    %else %do;
      data univar_result;
      set ParEst_&outcome_var.;
      run;
    %end;

  %end;
%mend;