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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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