- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello
I want to run logistic regression model that I want to test.
Before doing that I want to create the following 2 tables:
table 1-
Show for each exploratory variable the following statistics:
table 2-
show for each explanatory variable number of failures and no failures in each category.
When I run this code I get the results but it looks bad and not organized in one table.
When I do copy from results-sas report and paste it in excel then it looks not nice
please note that the explanatory variables are all categorical variables
ods html file="/usr/local/SAS/SASUsers/LabRet/UserDir/Q1234/freq_1.xls";
proc freq data=PANELCS_2211_Y_p_sample_7;
tables
(
X
W
Q
R
S
T
) * Failure_FUTURE_Ind
/ nopercent nocol chisq;
run;
ods html close;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
set sashelp.heart;
run;
%macro chisq_test(dsn=,x=,y=);
ods select none;
proc freq data=&dsn;
tables &x*&y /chisq ;
ods output ChiSq = ChiSq ;
run;
data ChiSq;
length var_name $ 40;
set ChiSq;
var_name="&y.";
drop table;
run;
ods select all;
proc append base=want data=ChiSq force;run;
%mend;
proc delete data=want;run;
%chisq_test(dsn=have,x=status,y=sex)
%chisq_test(dsn=have,x=status,y=bp_status)
%chisq_test(dsn=have,x=status,y=smoking_status)
Here is an example for second picture.Maybe you could make it macroize to do efficiently.
proc sql;
select ' Sex' as Var_name length=40,sex label='Category','Freq' as Measure length=40,
put(sum(status='Dead'),20. -l) as Failure,put(sum(status='Alive'),20. -l) as NoFailure,put(count(*),20. -l) as TOTAL
from have
group by sex
union all
select ' Sex' as Var_name,sex,'Row_PCT' as Measure,
put(sum(status='Dead')/count(*),percent8.2 -l) as Failure,put(sum(status='Alive')/count(*),percent8.2 -l) as NoFailure,'100%' as TOTAL
from have
group by sex
union all
select 'bp_status' as Var_name length=40,bp_status,'Freq' as Measure length=40,
put(sum(status='Dead'),20. -l) as Failure,put(sum(status='Alive'),20. -l) as NoFailure,put(count(*),20. -l) as TOTAL
from have
group by bp_status
union all
select 'bp_status' as Var_name,bp_status,'Row_PCT' as Measure,
put(sum(status='Dead')/count(*),percent8.2 -l) as Failure,put(sum(status='Alive')/count(*),percent8.2 -l) as NoFailure,'100%' as TOTAL
from have
group by bp_status
order by 1,2,3
;
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Details.
You show single variables but several of the tests you show could be using two (or more) variables.
So do you want single variable or x with w ?
Looks like Proc Freq and send the output to ODS OUTPUT to create data sets to merge if needed.
proc freq data=sashelp.class; tables sex age /chisq ; ods output onewaychisq = work.mychisq; run;
The output data set would need some manipulation, extract the variable name from the Table variable (scan works), the Label1 (or more) has values for the name of the statistic and a label. Use transpose to get your more desired output, or a report procedure.
You can use ODS TRACE to determine which objects are built by your code that you can select into data sets.
But this makes no sense:
show for each explanatory variable number of failures and no failures in each category.
Define failure and no failure. Where is the data that would be used to determine such???? What are the rules?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Ronein wrote:
You can see in my code that the tests are between each of independent variables x,w,q and so on and dependent variable Failure_FUTURE_Ind( indicator of failure)
Does not tell me how to interpret results as failure or not. Or which data is used or how. I try not to guess at such.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
set sashelp.heart;
run;
%macro chisq_test(dsn=,x=,y=);
ods select none;
proc freq data=&dsn;
tables &x*&y /chisq ;
ods output ChiSq = ChiSq ;
run;
data ChiSq;
length var_name $ 40;
set ChiSq;
var_name="&y.";
drop table;
run;
ods select all;
proc append base=want data=ChiSq force;run;
%mend;
proc delete data=want;run;
%chisq_test(dsn=have,x=status,y=sex)
%chisq_test(dsn=have,x=status,y=bp_status)
%chisq_test(dsn=have,x=status,y=smoking_status)
Here is an example for second picture.Maybe you could make it macroize to do efficiently.
proc sql;
select ' Sex' as Var_name length=40,sex label='Category','Freq' as Measure length=40,
put(sum(status='Dead'),20. -l) as Failure,put(sum(status='Alive'),20. -l) as NoFailure,put(count(*),20. -l) as TOTAL
from have
group by sex
union all
select ' Sex' as Var_name,sex,'Row_PCT' as Measure,
put(sum(status='Dead')/count(*),percent8.2 -l) as Failure,put(sum(status='Alive')/count(*),percent8.2 -l) as NoFailure,'100%' as TOTAL
from have
group by sex
union all
select 'bp_status' as Var_name length=40,bp_status,'Freq' as Measure length=40,
put(sum(status='Dead'),20. -l) as Failure,put(sum(status='Alive'),20. -l) as NoFailure,put(count(*),20. -l) as TOTAL
from have
group by bp_status
union all
select 'bp_status' as Var_name,bp_status,'Row_PCT' as Measure,
put(sum(status='Dead')/count(*),percent8.2 -l) as Failure,put(sum(status='Alive')/count(*),percent8.2 -l) as NoFailure,'100%' as TOTAL
from have
group by bp_status
order by 1,2,3
;
quit;