Rank-ordering output from proc logistic - sas

In the SAS proc logistic output, is there a way to rank-order by decreasing value of Wald's Chi square statistic?

Here's a link to an example of using ODS to write procedure output to a SAS dataset. The example uses proc genmod, but the concept applies to proc logistic as well. The documentation for proc logistic contains all of the ODS table names produced by the proc. Find the one you are interested in, write it out to a data set, and sort it however you desire.

Related

Exporting SAS data into SPSS with value labels

I have a simple data table in SAS, where I have the results from a survey I sent to my friends:
DATA Questionnaire;
INPUT make $ Question_Score ;
CARDS;
Ned 1
Shadowmoon 2
Heisenberg 1
Athelstan 4
Arnold 5
;
RUN;
What I want to do, using SAS, is to export this table into SPSS (.sav), and also have the value labels for the Question_Score, like shown in the picture below:
I then proceed to create a format in SAS (in hope this would do it):
PROC FORMAT;
VALUE Question_Score_frmt
1="Totally Agree"
2="Agree"
3="Neutral"
4="Disagree"
5="Totally Disagree"
;
run;
PROC FREQ DATA=Questionnaire;
FORMAT Question_Score Question_Score_frmt.
;
TABLES Question_Score;
RUN;
and finally export the table to a .sav file using the fmtlib option:
proc export data=Questionnaire outfile="D:\Questionnaire.sav"
dbms=spss replace;
fmtlib=work.Q1frmt;
quit;
Only to disappoint myself seeing that it didn't work.
Any ideas on how to do this?
You didn't apply the format to the dataset, unfortunately, you applied it to the proc freq. You would need to use PROC DATASETS or a data step to apply it to the dataset.
proc datasets lib=work;
modify questionnaire;
format Question_Score Question_Score_frmt.;
run;
quit;
Then exporting will include the format, if it's compatible in SAS's opinion with SPSS's value label rules. I will note that SAS's understanding of SPSS's rules is quite old, based on I think SPSS version 9, and so it's fairly often that it won't work still, unfortunately.

SAS RobustReg Procedure output parameter estimates [duplicate]

Running complex procs such as PROC REG or PROC GLM, there are often tables that are produced in the output window describing the results of the regression, in addition to the output datasets produced using OUT or OUTPUT options.
How can I output those tables to SAS datasets?
For example, given the first SAS example in PROC REG (on the documentation page), how can I output the Goodness of Fit Statistics (such as the R-Squared)?
In order to identify possible output datasets, SAS provides the ods trace statement. This asks SAS to write to the log the name (and some details) of each data table it writes to the output. In most cases, this can be saved to a dataset via ods output.
For example, in the SAS example referred to in the question, you could write:
ods trace on;
proc reg data=baseball;
id name team league;
model logSalary = no_hits no_runs no_rbi no_bb yr_major cr_hits;
run;
ods trace off;
That would report in the log that "FitStatistics" is the name of the output object you want. Then you write:
ods output FitStatistics=fitds;
proc reg data=baseball;
id name team league;
model logSalary = no_hits no_runs no_rbi no_bb yr_major cr_hits;
run;
and it will output the fitds dataset.
ODS Trace is only needed for the purpose of determining the name of the table of course - once you know the name of the table you need, you can simply use that name with ods output in the future.
You also frequently can find the list of the table names in the documentation; for example, PROC REG places them here.
ODS Output may be placed any location before the run statement (as it is a global statement); a common location is immediately before run. My personal preference is to put it before the proc as it is a global statement, but there is some disagreement with that approach.

How do I see what output options are available in my proc?

Running complex procs such as PROC REG or PROC GLM, there are often tables that are produced in the output window describing the results of the regression, in addition to the output datasets produced using OUT or OUTPUT options.
How can I output those tables to SAS datasets?
For example, given the first SAS example in PROC REG (on the documentation page), how can I output the Goodness of Fit Statistics (such as the R-Squared)?
In order to identify possible output datasets, SAS provides the ods trace statement. This asks SAS to write to the log the name (and some details) of each data table it writes to the output. In most cases, this can be saved to a dataset via ods output.
For example, in the SAS example referred to in the question, you could write:
ods trace on;
proc reg data=baseball;
id name team league;
model logSalary = no_hits no_runs no_rbi no_bb yr_major cr_hits;
run;
ods trace off;
That would report in the log that "FitStatistics" is the name of the output object you want. Then you write:
ods output FitStatistics=fitds;
proc reg data=baseball;
id name team league;
model logSalary = no_hits no_runs no_rbi no_bb yr_major cr_hits;
run;
and it will output the fitds dataset.
ODS Trace is only needed for the purpose of determining the name of the table of course - once you know the name of the table you need, you can simply use that name with ods output in the future.
You also frequently can find the list of the table names in the documentation; for example, PROC REG places them here.
ODS Output may be placed any location before the run statement (as it is a global statement); a common location is immediately before run. My personal preference is to put it before the proc as it is a global statement, but there is some disagreement with that approach.

SAS output confidence interval to plot for strata variable after logistic regression

I want to put all confidence interval plot in one plot for all strata variable after logistic regression. For example, my SAS code is:
proc logistic data=data1;
model y = x;
strata cv1;
output out=out1 unknown1=x_beta1 unknown2=lowerbound unknown3=upperbound unknown4=strata_variable;
run;
I do not know what variable names(unknown1 unknown2 unknown3) I can use in the output statement. As in the sas support page, it said "If a STRATA statement is specified, only the PREDICTED=, DFBETAS=, and H= options are available",here is the link.
My plot statement will be:
proc sgplot data=out1;
scatter y=strata_variable x=x_beta1 / xerrorlower=lowerbound xerrorupper=upperbound
markerattrs=(symbol=circlefilled size=9);
run;
The first plot in this page shows exactly what I want. Sorry I cannot insert any plot as my reputation is not high enough.
I find an another way to finish this. I wrote a macro do loop to get every strata data. And then added
ods output OddsRatios=odds_temp;
to get the estimation and confidence interval and merger all the strata together to make the plot I need.

How to export selected p-values to the table in SAS?

I'm trying to write a program in SAS that supports decision-making process in selecting the best formula of linear regression model. I even had one but in R environment. Now I have to implement it in SAS. The final result should be a dataset with each line decribing different regression formulas i.e. names of explanatory variables, R-squared, p-values for different statistical tests, etc.
As an example, one of the tests is Durbin-Watson test for autocorrelation. My goal is to insert a p-value into the table I've mentioned. I use the code:
proc reg data=indata outest=outdata EDF ridge=0 OUTVIF;
model PKB = PK INV SI / DW;
run;
quit;
And as a result I get in the output window:
Durbin-Watson Statistics
Order DW Pr < DW Pr > DW
1 1.2512 0.0038 0.9962
I want to insert those p-values directly into the SAS table. I tried to find an answer in the SAS OnlineDoc and on the forum but with no success.
ODS OUTPUT is the best way to get information that you can print to the screen into datasets. Use ODS TRACE ON; before your code, run it, then inspect the log; see what table name matches what you're looking for. Then use ODS OUTPUT <tablename>=<datasetname>.
For example, in this PROC FREQ, I see ONEWAYFREQS is the table I want.
ods trace on;
proc freq data=sashelp.class;
var age;
run;
ods trace off;
So I use ODS OUTPUT:
ods output onewayfreqs=ages;
proc freq data=sashelp.class;
table age;
run;
ods output close;
and get a nice dataset. (ODS TRACE is not necessary if you know the name of the table you're looking for.)