I have a dataset with Yes / No values.
I've figured out that I can use Proc Freq to generate a table of "One-Way" results which displays the proportion per row i.e. 60% yes, 40% no. However, this is shown in a pop-up window by default.
I want to save these results to a dataset for potential manipulation but I can't figure it out. Searching online it says I need to enter additional commands in the table and output statement for this to work. This is my sample (incorrect) code:
proc freq data = results noprint;
tables check / pct_row;
output out = table1;
run;
Close, the OUT goes after the / on the TABLES statement.
proc freq data = results noprint;
tables check / out=table1 pct_row outpct;
run;
Related
I'm using the following code to do a chi-square test in SAS.
proc freq data=data;
tables var1*var2/chisq;
run;
It gives the output of both chi-square and Fisher's Test. Anyway to only include chi-square test in the output?
You can use ODS SELECT/EXCLUDE to control what is displayed. If you don't want the fishers test you can exclude that table, assuming the table name is FISHERSEXACT.
ods exclude fishersexact;
Alternatively you can select in only the tables you want and everything else is excluded by default.
ods select crosstabfreqs chisquare;
I do not think you can supress printing some of the tables in PROC FREQ; it seems to me you can supress all, or none.
However, still you can work as follows:
First, do a one-off investigation: issue the ods trace on / label before your statement so that the Log contains labels of the ODS tables:
ods trace on / label;
proc freq data=data;
tables var1*var2/chisq;
run;
ods trace off;
Alternatively, find the name of your table in PROC FREQ docs.
Once you know the table name, run your code again but this time save the respective ODS table to a regular table. This is done by issuing ods output <ODS=table-name>= <table-to-save-it-into>; in front of your command. Assuming you want to save the ChiSq table the code looks like:
ods output ChiSq=work.my_chisq_table;
proc freq data=data;
tables var1*var2/chisq;
run;
The chi-square table will be saved as work.my_chisq_table and you can print it elsewhere.
I need to perform a procedure on a small set (e.g. 100 rows) of a very big table just to test the syntax and output. I have been running the following code for a while and it's still running. I wonder if it is doing something else. Or what is the right way to do?
Proc sql inobs = 100;
select
Var1,
sum(Var2) as VarSum
from BigTable
Group by
Var1;
Quit;
What you're doing is fine (limiting the maximum number of records taken from any table to 100), but there are a few alternatives. To avoid any execution at all, use the noexec option:
proc sql noexec;
select * from sashelp.class;
quit;
To restrict the obs from a specific dataset, you can use the data set obs option, e.g.
proc sql;
select * from sashelp.class(obs = 5);
quit;
To get a better idea of what SAS is doing behind the scenes in terms of index usage and query planning, use the _method and _tree options (and optionally combine with inobs as above):
proc sql _method _tree inobs = 5;
create table test as select * from sashelp.class
group by sex
having age = max(age);
quit;
These produce quite verbose output which is beyond the scope of this answer to explain fully, but you can easily search for more details if you want.
For further details on debugging SQL in SAS, refer to
http://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/viewer.htm#a001360938.htm
proc mean data =table A mean;
var interestRate;
run;
The variable interest rate is already in percentage format in table A. But the proc means doesn't return the results in percentage.
How to get the mean interst rate in percentage format when doing the proc means?
I don't believe there's any way to format the output directly. You can use a format statement to change how the data would be formatted in an output dataset, and then use PROC REPORT or similar to produce output similar to PROC MEANS output. You might also consider PROC TABULATE if it's a fairly simple table.
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.)
ods html file = "Y:/cars/cars.xls";
proc sql;
title "Cars";
select
make,model,type,origin,drivetrain
from sashelp.class
where engine size gt 3;
quit;
Suppose after run above query in SAS I will get output in excel format.
So, how it is possible to get same ouput via proc report step?
You wouldn't get much output from that since there aren't any cars in sashelp.class.
The basic proc report step will look something like:
title "Cars";
proc report data=sashelp.cars nowd;
where enginesize gt 3;
columns make model type origin drivetrain;
run;
I wouldn't use PROC REPORT though just to do this - the point of PROC REPORT is all of the other features you can use, between the formatting options, the summarization options, etc.