combine proc sql step in proc report to create report in excel - sas

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.

Related

SAS only include chi-square output in proc freq

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.

Jupyter notebook display SAS output word-wrapper

I have a table in sas format (.sas7bdat) and would like to output it in Jupyter notebook.
proc print data=dataBoxE.my_data (firstobs=2 obs=12);
run;
The output table is jammed together since it has 100+ columns. How should I setup the environment within my notebook?
Moreover, is there a way to save the log file instead of opening it right away in the output cell? Thanks.
In SAS you can change the location of where the log file is created using proc printto; Documentation here.
When using proc printto, don't forget to reset the location to the default system value at the end of your, Example:
proc printto log='c:\em\log1.log';
run;
/* Your code here */
proc printto;
run;
If you don't need the 100+ columns; then select only the ones you want using the VAR statement in proc print Documentation here :
proc print data=exprev;
var country price sale_type;
run;
If you want all the 100+; just export them to csv using proc export and view them in any spreadsheet reader to avoid crashing your browser. Documentation here.
proc export data=sashelp.class
outfile='c:\myfiles\Femalelist.csv'
dbms=csv
replace;
run;

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.

Is it possible to limit the numbers of observations per page for proc report

I am just wondering if there are any options can be used to limit the number of observations printed per page in Proc Report procedure?
Thank you
This depends in part on the destination.
PROC REPORT in page-sensitive destinations, like ODS LISTING or ODS PDF, can be convinced to limit observations a few ways.
ODS LISTING: OPTIONS PS=[#] will set the page size. PS option on PROC REPORT statement also does this. See PROC REPORT statement for more.
ODS PDF, ODS RTF, other page-sensitive destinations: Create a page variable that stores which page an observation falls on.
ods pdf;
data cars;
set sashelp.cars;
if mod(_n_,20)=0 then page_num+1;
run;
proc report data=cars;
columns make model page_num;
define page_num/ order noprint;
break after page_num/page;
run;
ods pdf close;

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.)