I have the dataset below, and I want to know if there is a difference in Response between SoilTest, Irrigati, MowHeigh and Clipping, but I want to use the long format of the data:
data data;
input Practice $ Student $ Response $;
datalines;
SoilTest a Yes
SoilTest b No
SoilTest c Yes
SoilTest d Yes
SoilTest e No
SoilTest f Yes
SoilTest g Yes
SoilTest h Yes
SoilTest i No
SoilTest j Yes
SoilTest k Yes
SoilTest l Yes
SoilTest m Yes
SoilTest n Yes
Irrigation a Yes
Irrigation b No
Irrigation c No
Irrigation d No
Irrigation e No
Irrigation f No
Irrigation g No
Irrigation h No
Irrigation i Yes
Irrigation j No
Irrigation k No
Irrigation l No
Irrigation m No
Irrigation n No
MowHeight a Yes
MowHeight b No
MowHeight c Yes
MowHeight d Yes
MowHeight e Yes
MowHeight f Yes
MowHeight g Yes
MowHeight h Yes
MowHeight i No
MowHeight j Yes
MowHeight k Yes
MowHeight l Yes
MowHeight m Yes
MowHeight n Yes
Clippings a Yes
Clippings b No
Clippings c No
Clippings d Yes
Clippings e Yes
Clippings f No
Clippings g No
Clippings h Yes
Clippings i Yes
Clippings j Yes
Clippings k Yes
Clippings l No
Clippings m Yes
Clippings n No
;
run;
Actually this code working, but with changing the shape of the table:
proc sort data=data;by student;run;
proc transpose data=data out=data_test(drop=_NAME_);
ID Practice;
BY student;
VAR Response;
run;
proc freq data=data_test;
tables SoilTest Irrigati MowHeigh Clipping/nocum;
tables SoilTest*Irrigati*MowHeigh*Clipping/agree noprint;
run;
is there any possibility to have the same pvalue of Cochran test, without changing the shape of the data, it means :using the long format of data without doing transpose ?
You can use programming to generate the table statements.
proc sort;
by student practice;
run;
proc transpose data=data out=data_test(drop=_NAME_);
ID Practice;
BY student;
VAR Response;
run;
proc print;
run;
proc transpose data=data_test(obs=0 drop=Student) out=practice;
var _all_;
run;
proc sql noprint;
select _name_,_name_ into :agree SEPARATED '*',:oneway SEPARATED ' ' from practice;
quit;
%put NOTE: &=agree &=oneway;
proc freq data=data_test;
tables &oneway / nocum;
tables &agree/agree ;
run;
@tSAS1 wrote:
Hello thanks @FreelanceReinh
Actually I want to use that code in a macro, so it will not be easy to enter each variable (modalities of Practice variable) in proc freq
Hello @tSAS1,
I believe that a DATA step can be used to compute the test statistic and p-value, as was demonstrated for a different dataset in Re: Computing multiway tables using indexed variables and proc freq. But I'm not sure why you wouldn't use your existing approach using PROC TRANSPOSE and PROC FREQ, unless your real dataset is much larger so that the DATA step might outperform PROC FREQ.
Hello thanks @FreelanceReinh
Actually I want to use that code in a macro, so it will not be easy to enter each variable (modalities of Practice variable) in proc freq
You can use programming to generate the table statements.
proc sort;
by student practice;
run;
proc transpose data=data out=data_test(drop=_NAME_);
ID Practice;
BY student;
VAR Response;
run;
proc print;
run;
proc transpose data=data_test(obs=0 drop=Student) out=practice;
var _all_;
run;
proc sql noprint;
select _name_,_name_ into :agree SEPARATED '*',:oneway SEPARATED ' ' from practice;
quit;
%put NOTE: &=agree &=oneway;
proc freq data=data_test;
tables &oneway / nocum;
tables &agree/agree ;
run;
@tSAS1 wrote:
Hello thanks @FreelanceReinh
Actually I want to use that code in a macro, so it will not be easy to enter each variable (modalities of Practice variable) in proc freq
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!
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.
Ready to level-up your skills? Choose your own adventure.