DATA Step, Macro, Functions and more

inserting column name into existing table

Reply
New Contributor
Posts: 2

inserting column name into existing table

I'd like to develop a macro in which I can collect summary chi p value statistic for columns within my dataset (see code below). I'm trying to use %quote(&col) within a proc sql statement to insert the column name captured within a %do loop, but when I look at the resulting table, all I've captured is "&col". Does anyone have any advice?

Thanks.

proc sql;
select name into :chi_list separated by ' '
from model.metaclass
where format = '$' *identifies categorical variables;

%wordcount(&chi_list) *macro that generates the number of words in the list;

%macro chi_test;
%local col;
%do i = 1 %to &count;
let col = %scan(&chi_list,&i);

proc freq data = model.model_data;
tables &col / out = model.frq_&col2 chisq cellchi2;
by &resp; *referenced by outer macro process;
output out = model.chi_&col. chisq;
run;

proc sql;
insert into model.chisq_p;
select %quote(&col), P_PCHI from model.chi_&col.;
quit;
Valued Guide
Posts: 2,175

Re: inserting column name into existing table

%quote() provides macro quoting
To obtain the value that is in &col, use
select "&col" length=32 as col, P_PCHI from model.chi_&col
New Contributor
Posts: 2

Re: inserting column name into existing table

That worked - thanks a lot!
Ask a Question
Discussion stats
  • 2 replies
  • 116 views
  • 0 likes
  • 2 in conversation