BookmarkSubscribeRSS Feed
myles4569
Calcite | Level 5
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;
2 REPLIES 2
Peter_C
Rhodochrosite | Level 12
%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
myles4569
Calcite | Level 5
That worked - thanks a lot!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 857 views
  • 0 likes
  • 2 in conversation