Is it usual that the Univariate Frequencies does not display the BY-variable while Univariate BasicMeasures does show the BY-variable?
In the example below I load in some data and want to show gas prices by zipcode. The output for PROC FREQ shows the BY-variable (zipcode) in the output as does the UNIVARIATE BasicMeasures. But the UNIVARIATE Frequencies is not showing the BY-variable in the output.
Am I doing something wrong? I've even set the templates to default, with the ODS PATH statement, in case the templates got messed up by other code (or other coders using same account).
DATA prices;
INPUT zipcode price;
DATALINES;
90066 3.10
90066 3.17
90066 3.26
98101 2.99
98101 3.06
98101 3.16
;
run;
proc sort;
by zipcode;
run;
ods path sashelp.tmplmst(read) ;
ods pdf file = "gasprices.pdf";
PROC FREQ data = prices;
tables price;
by zipcode;
run;
ods select Frequencies;
PROC UNIVARIATE data = prices freq;
var price;
by zipcode;
run;
ods select BasicMeasures;
PROC UNIVARIATE data = prices;
var price;
by zipcode;
run;
ods pdf close;
You can specify more than one object in the ODS SELECT, so you could pull both tables out of the same PROC FREQ like this:
ods pdf file = "gasprices.pdf";
ods select BasicMeasures Frequencies;
PROC UNIVARIATE data = prices freq;
var price;
by zipcode;
run;
ods pdf close;
I know that doesn't exactly solve your problem, but it looks to me like the BY-variable display just isn't properly linked to the PROC UNIVARIATE frequency tables (e.g., try ODS SELECT Moments - works fine). Might be worth reporting to SAS.
Related
I am using ODS to output an rtf file with graphs for each warehouse, using the warehouse ID as the by value. I need to organize the graphs in ascending order of rejected products per 100 produced. I was reordering the graphs manually in Word, but now I am being asked to produce this for the top 20 warehouses instead of the top 5 and would prefer not to do this manually. I've created a variable (norder) to indicate the ranking of each warehouse, but if I sort by this or try to use it as a by value, it messes up the graphs. I have also tried the NOTSORTED option, but this did not work. Is there an easy way to do this? Below is my code:
proc transpose data=WIDE_war
out=Long_war(rename=(Col1=Value))
name=source;
by norder ID name county zipcode date;
var defect1 defect2;
run;
proc sort data=long_war; by ID name zipcode county; run;
OPTIONS orientation=landscape nodate;
ods rtf file="C:\Users\....Top_10_Warehouse.rtf" STYLE=Styles.rtf bodytitle STARTPAGE=NO;;
ods listing close;
ods noproctitle ;
ODS ESCAPECHAR='^';
title; footnote;
title;
ods graphics on / height=7in width=9in;
ods graphics/noborder;
/*Table*/
/*List name, ID, number of products produced, number of defects, the rate of defects per 100 units produced */
/*sort by descending order of the last number */
ods rtf text= "^{style[fontweight=bold just=c fontsize=14pt]Warehouses with the greatest number of defects per 100 units produced}";
proc sort data=req4; by descending rejrat2; run;
proc print data=req4 noobs label;
var ID name ZIPcode County;
var mean_prod newdefects rejrat2 /style(data)={ width=1in};
run;
* time trend plots;
ods rtf startpage=NOW;
ods rtf text= "^{style[fontweight=bold just=c fontsize=14pt] Trend plot of the warehouses listed in the above table since June 01, 2020}";
proc sgplot data=long_war;
by ID name county ;
title1 "ID= #byval(ID) ";
title2 "Name: #byval(name) ";
title3 "County: #byval(county) ";
vbar date/ response=Value group=source groupdisplay=stack grouporder=data NOOUTLINE;
xaxis type=linear thresholdmin=0 label="Date"
values=('01jun20'd to '13dec20'd by 7)
labelattrs=(size=12pt weight=bold)
valueattrs=(size=13pt);
yaxis min=0 label="Count" INTEGER grid
labelattrs=(size=12pt weight=bold)
values=(0 to 35 by 5)
valueattrs=(size=13pt) fitpolicy=thin offsetmin=0 ;
label Source = "Defects by type"
Value = "Count";
options NOBYLINE;
run;
ods rtf close;
ods listing ;
I am looking to have SAS calculated the predicted R-squared value using PROC REG.
You mean the R-Square? It's very easy to get.
ods output FitStatistics = FitStatistics;
proc reg data = sashelp.class;
model height = age;
quit;
ods output close;
The R-Square is located at data set FitStatistics.
I want to output my SAS regression result into excel.
The code is:
proc import datafile = 'cmds.csv'
out = Work.cmds
dbms = CSV;
run;
ODS TAGSETS.EXCELXP
file="dt.xls";
STYLE = STATISTICAL;
proc sort data=Work.Cmds out=Work.Cmds;
by year;
run;
proc reg data=Work.Cmds outest=want tableout;
by year;
model Investment = Size Growth_New Leverage complex Deficit pc_income_NEW Density/hcc adjrsq ;
ods output parameterestimates=want2;
run;
ODS TAGSETS.EXCELXP CLOSE;
Although it successfully generates the excel file, it contains many sheets. I want to generate all things in one sheet. How can I do?
There are options within the tagsets, in specific sheet_interval. To have all go to one page, set the sheet interval option to none.
ODS TAGSETS.EXCELXP file="dt.xls" STYLE = STATISTICAL options (sheet_interval='none');
However, TAGSETS.EXCELXP generates an XML file, not an Excel file. If you have SAS 9.4 TS1M4+ then I would recommend ODS EXCEL instead.
ods excel file="dt.xlsx" style=statistical options (sheet_interval = 'none');
List of all options for ODS TAGSETS.EXCELXP is here:
https://support.sas.com/rnd/base/ods/odsmarkup/excelxp_help.html
Full example that will generate a single tab:
ods tagsets.excelxp file='C:\_localdata\demo.xls' options(sheet_interval='none');
proc sort data=sashelp.cars out=cars;
by origin;
run;
proc reg data=cars outest=demo tableout;
by origin;
model mpg_city = mpg_highway invoice cylinders;
ods output parameterEstimates=want;
run;
ods tagsets.excelxp close;
I have to export some data in the format of two tables per row, with multiple rows. So far I have got as far as building a report with multiple tables stacked on top of each other, but with only one per row by using multiple proc report statements in a code statement as so:
proc report data = mydata; title 'My Title:'; run;
proc report data = mydata; title 'My Title:'; run;
proc report data = mydata; title 'My Title:'; run;
What do I need to add/amend so that I get two tables per row in my report?
Thanks
Some destinations support this directly in the ODS statement; like ODS PDF.
ods pdf file="test.pdf" columns=2 ;
proc print data=sashelp.class;
run;
proc freq data=sashelp.class;
tables age;
run;
ods pdf close;
However, HTML doesn't. For those you'll want to use ODS LAYOUT.
ods html file="test.html";
ods layout gridded
columns=2;
ods region;
proc print data=sashelp.class;
run;
ods region;
proc freq data=sashelp.class;
tables age;
run;
ods layout end;
ods html close;
See the ODS Layout Tip Sheet for more details.
ODS LAYOUT won't work with ODS EXCEL, sadly. You can use this macro to do something similar, if you prefer, or perhaps use PROC DOCUMENT to get the tables together, but I'm not sure exactly how that would work.
If you want more than one table in each column, then you can either have one ODS REGION per table (they'll end up being alternated l-r-l-r) or you can just add more to the two ODS REGIONs here if you don't need them to be gridded properly.
IE:
ods html file="test.html";
ods layout gridded
columns=2;
ods region;
proc print data=sashelp.class;
run;
ods region;
proc freq data=sashelp.class;
tables age;
run;
ods layout end;
ods html close;
Those just have two columns with 2 tables in each column, but they're not aligned.
ods html file="test.html";
ods layout gridded
columns=2;
ods region;
proc print data=sashelp.class;
run;
ods region;
proc freq data=sashelp.class;
tables age;
run;
ods region;
proc print data=sashelp.cars;
run;
ods region;
proc freq data=sashelp.cars;
tables origin;
run;
ods layout end;
ods html close;
This has a proper grid layout.
I resolved this in the end by tweaking the above as so:
ods layout gridded columns=2 rows=2;
ods region;
proc print data=sashelp.class;
run;
ods region;
proc freq data=sashelp.class;
tables age;
run;
ods region;
proc print data=sashelp.cars;
run;
ods region;
proc freq data=sashelp.cars;
tables origin;
run;
ods layout end;
Obviously, rows and columns will change depending on your needs. This produces a SAS report, that I then exported as a step in the project as a HTML file.
Thanks
I'm trying to hide the titles for each by group in my ODS output. Code:
ods noproctitle;
ods html ;
proc sort data=sashelp.class out=class;
by sex;
run;
proc freq data=class;
by sex;
tables sex / list;
run;
Specifically, the titles I'm trying to hide are:
Sex=F
and
Sex=M
Look at the BYLINE/NOBYLINE option.
options nobyline;
Here's the documentation reference
http://support.sas.com/documentation/cdl/en/lesysoptsref/69799/HTML/default/viewer.htm#n1hr2wb7h5g6twn1gtt5r4zjsg39.htm