Hello
I used Pairwise_chisq, but some output files like Chitest have no observations. I tried many times, but it did not work. Did any one use it before?
I referred to this paper: http://support.sas.com/resources/papers/proceedings14/1544-2014.pdf.
Thank you.
If you post your full code with some sample data and how you called it I'll take a look at it.
@xzhang wrote:
Hello
I used Pairwise_chisq, but some output files like Chitest have no observations. I tried many times, but it did not work. Did any one use it before?
I referred to this paper: http://support.sas.com/resources/papers/proceedings14/1544-2014.pdf.
Thank you.
@xzhang wrote:
Hello
I used Pairwise_chisq, but some output files like Chitest have no observations. I tried many times, but it did not work. Did any one use it before?
I referred to this paper: http://support.sas.com/resources/papers/proceedings14/1544-2014.pdf.
Thank you.
Doesn't work is awful vague.
Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.
No output? Post any log in a code box.
Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
Thank you for reply. Here are the codes
proc freq data=a;
tables b*c/chisq nocol norow nopercent out=d;
run;
proc contents data=d;
run;
data d; set d;
b=STRIP(put(b_c,8.));
c=STRIP(put(c_c,8.));
run;
proc contents data=d;
run;
%macro Pairwise_Chisq(data=, group=, outcome=, count=);
proc freq data=&data noprint;
table &group/out=out_group;
run;
data groupID;
set out_group;
GID=_n_;
run;
data _null_;
set groupID nobs=nobs;
call symput('num_group', compress(put(nobs, 11.)));
stop;
run;
data ChiTest; *store pairwise Chisquare statistics to this;
stop;
run;
%Do group1=1 %to &num_group-1; *for each pair obtain chisquare stat;
%Do group2=&group1+1 %to &num_group;
data group_pair;
set groupID;
if GID EQ &group1 then call symput('name_group1', type);
if GID EQ &group2 then call symput('name_group2', type);
run;
proc freq data=&data noprint; output PCHI out=CTout ;
tables &group*&outcome /chisq cellchi2 nopercent;
where &group in ("&name_group1", "&name_group2");
weight &count;
run;
data CTout1;
set CTout;
PAIR_COMPARED="&name_group1"||" vs "||"&name_group2";
run;
data ChiTest;
set ChiTest CTout1;
run;
%End;
%End;
data ChiTest; *rename variables for final results;
set ChiTest;
CHI_STAT=_PCHI_; DF=DF_PCHI; P_VALUE=P_PCHI;
keep pair_compared Chi_stat DF p_value;
run;
%mend Pairwise_Chisq;
%Pairwise_Chisq(data=d,group=b_c,outcome=c_c,count=count);
_________________________________________________________________
no output, only output 5 sas files.
there were something I edited wrong. Here is the right one.
data d; set d;
b_c=STRIP(put(b,8.));
c_c=STRIP(put(c,8.));
run;
Where does A come from? Sample data please.
A is raw data, b (3 levels) and c (3 levels) are two categorical variables. like:
Id b c
1 15 0
2 16 1
3 17 2
4 16 0
..............
I need data to run it with. 4 lines won't be enough.
One potential issue is the use of comments like:
*store pairwise Chisquare statistics to this;
Inside a macro the comments should
%*store pairwise Chisquare statistics to this;
or
/*store pairwise Chisquare statistics to this*/
This data step has issues because the data set groupid has no variable named type.
data work.group_pair; set work.groupID; if GID EQ &group1 then call symput('name_group1', type); if GID EQ &group2 then call symput('name_group2', type); run;
so the values for the name_group macro variables are blank. And therefore the proc freq fails as no values of the group variable will match the blanks in &name_group1 and 1.
proc freq data=&data noprint; output PCHI out=work.CTout ; tables &group*&outcome /chisq cellchi2 nopercent; where &group in ("&name_group1", "&name_group2"); weight &count; run;
Thank you sooooooooooo..much! I changed the name "type" to the corresponding variable name in my data. It is working now. Much appreciated!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.