My boss would like me to create a chart and table in SAS similar to something you can produce in excel, where the data table sits below the chart. This would mean using the data on the x-axis and placing more data below it.
Desired output
(chart area) (Row 1) Building 1 Building 2 Building 3 Building 4
(Row 2) 333 267 234 235
(Row 3) 3232 213 3215 657
I'm not sure how to do this in proc report, where the data runs long, instead of wide. Also, the data set is long:
Building ID var1 var2
Building 1 333 3232
Building 2 267 213
CarolinaJay's suggestion of a PROC GCHART or SGPLOT or whatnot followed by another proc is the way to go, IMO; while you could do both at once, it's a lot more work to do so.
To accomplish your specific table, I recommend PROC TABULATE; it doesn't care what direction your data goes.
data have;
informat buildingID $12.;
input BuildingID $ var1 var2;
datalines;
Building1 333 3232
Building2 267 213
;;;;
run;
proc tabulate data=have;
class buildingID;
var var1 var2;
tables (var1 var2)*sum=' ', buildingID=' ';
run;
Plop that under a plot, and you have something like this (I have no idea how to plot this so I just picked something totally at random):
ods _all_ close;
ods html;
data have;
informat buildingID $12.;
input BuildingID $ var1 var2;
datalines;
Building1 333 323
Building2 267 213
;;;;
run;
proc sgplot data=have;
vbar var1/response=var2 group=buildingID;
run;
title;
proc tabulate data=have;
class buildingID;
var var1 var2;
tables (var1 var2)*sum=' ', buildingID=' ';
run;
ods html close;
Related
I have the following data
DATA HAVE;
input year dz $8. area;
cards;
2000 stroke 08
2000 stroke 06
2000 stroke 06
;
run;
After using the proc freq
proc freq data=have;
table area*dz/ list nocum ;
run;
I get the below output
I want to replace any values below 5 in "frequency" column and 0 in "percent" column with "<5" and "0", respectively.
I have the below proc format code
proc format;
picture count (round)
0-4 = ' <5' (NOEDIT);
picture pcnt (round)
0 = ' - '
other = '009.9%';
But I am not understanding how to use it in the data step to get the desired results. Please guide.
Thanks!
You can save the result of proc freq as a dataset then report it as your wish.
proc freq data=have noprint;
table area*dz/ list nocum out = want;
run;
proc print;
format COUNT count. PERCENT pcnt.;
run;
If you want your proc freq output result just as your wish, not using an extra report or print procedure, you need to code a little more. The answer is about ods style and there is a very nice article about it: Using Styles and Templates to Customize SASĀ® ODS Output
I have the following data
DATA HAVE;
input year dz area;
cards;
2000 1 08
2000 1 06
2000 1 06
;
run;
proc freq data=have;
table area*dz / norow nocol;
run;
I get the following output
I would like to format it to put frequency in one column and percent in another column and I don't want the total column. Is there a way to do it?
Thank you!
Try adding the LIST option to get a different layout:
proc freq data=have;
table area*dz / norow nocol LIST;
run;
Pipe it to a data set and format as desired:
proc freq data=have;
table area*dz / norow nocol LIST out=want;
run;
proc print data=want;run;
Use PROC TABULATE instead (not shown), which allows you more control over your layout and formats.
I have an example of a dataset in the following manner
data have;
input match percent;
cards;
0 34
0 54
0 33
0 23
1 60
1 70
1 70
1 70
;
Essentially I want to sum the observations that are associated with 0 and then divide them by the number of 0s to find the average.
e.g 34+54+33+23/4 then do the same for 1's
I looked at PROC TABULATE. However, I don't understand how to carry out this procedure.
Many ways to do this in SAS. I would use PROC SQL
proc sql noprint;
create table want as
select match,
mean(percent) as percent
from have
group by match;
quit;
You can use proc means and you will the mean plus a bunch of other stats:
more examples here for proc means.
proc means data=have noprint;
by match;
output out=want ;
Output:
This can be done very easily using proc summary or proc means.
proc summary data=have nway missing;
class match;
var percent;
output out=want mean=;
run;
You can also output a variety of other statistics using these procedures.
I am running fast cluster process in Sas.
The frequency value i get is in Scientific form in excel output i get. I dont want it. What part of code I should change. Attached below is the snipeet of my code and the output I am getting
%MACRO LOOP(Start,End);
%DO MAXC=&Start %TO &End;
ODS HTML PATH="J:\DIAC-CITI\Client_Data\CARDS\03 Analysis\Clustering\Pre-Optimization\Output\Cluster Outputs"
BODY="MaxCluster&MAXC..xls"
STYLE=DEFAULT;
ODS LISTING CLOSE;
OPTIONS NOLABEL;
PROC FASTCLUS
DATA=Pre_Modeling
OUT=test
MAXCLUSTERS=&MAXC
MAXITER=100;
OUTSTAT=stat&maxc;
FREQ FREQUENCY;
WEIGHT REGIONAL_WTS;
VAR RISK_SCORE;
TITLE ' ';
RUN;
ODS HTML CLOSE;
ODS LISTING;
data stat&maxc;
set stat&maxc(rename=( _type_=type));
where type in('RSQ','PSEUDO_F','CCC');
run;
proc sort data=stat&maxc;
by type;
run;
proc transpose data=stat&maxc out=stat&maxc prefix=value&maxc.;
by type;
var over_all;
run;
%END;
%MEND LOOP;
%LOOP(1,30)
Output
Cluster Frequency
1 69
2 2295564
4 172098
6 6
9 6941
12 32
18 872126
8 4.56E+07
16 34347
17 1.98E+07
15 9568079
10 8824842
7 9669026
3 5855012
5 3353213
11 876159
13 313310
14 202065
19 33736
The frequency I am getting is in scientific form. I dont want that.If I change it to number in excel, it gets rounded off and the original number gets lost.
Can anyone help me
When I added format to the code
PROC FASTCLUS
DATA=Pre_Modeling
OUT=test
MAXCLUSTERS=22
MAXITER=100
OUTSTAT=stat22;
FREQ frequency format best16. ;
WEIGHT REGIONAL_WTS;
VAR RISK_SCORE;
TITLE ' ';
RUN;
PROC FASTCLUS
DATA=Pre_Modeling
OUT=test
MAXCLUSTERS=22
MAXITER=100
OUTSTAT=stat22;
FREQ format frequency best16. ;
WEIGHT REGIONAL_WTS;
VAR RISK_SCORE;
TITLE ' ';
RUN;
Both the codes did not run and it gave an error.
Format statement should be put in the last section of your code: Proc Transpose.
proc transpose data=stat&maxc out=stat&maxc prefix=value&maxc.;
by type;
var over_all;
format over_all best16.;
run;
I'm trying to get all dataset names in a library in to a data set.
proc datasets library=LIB1 memtype=data ;
contents data=_all_ noprint out=Datasets_in_Lib1(keep=memname) ;
run;
The final data set (Datasets_in_Lib1) is having all the data set names that are in LIB1, but names are truncated to 6 characters.Is there any way to get full names of the datasets with out truncation.
Ex: If dataset name is x123456789, the Datasets_in_Lib1 will have x12345 only.
Thanks in advance,
Sam.
Agree with the comment, in 9.3 memname is $32. I don't think there was a version of SAS where data set names were limited to 6 characters. They went from 8 characters to 32 characters in v7 (I think).
Here's a log from running your code, showing it works as you want in 9.3
51 data work.x123456789;
52 x=1;
53 run;
NOTE: The data set WORK.X123456789 has 1 observations and 1 variables.
54
55 proc datasets library=work memtype=data nolist;
56 contents data=_all_ noprint out=Datasets_in_Lib1(keep=memname) ;
57 run;
NOTE: The data set WORK.DATASETS_IN_LIB1 has 1 observations and 1 variables.
58
59 data _null_;
60 set Datasets_in_Lib1;
61 put _all_;
62 run;
MEMNAME=X123456789 _ERROR_=0 _N_=1
NOTE: There were 1 observations read from the data set WORK.DATASETS_IN_LIB1.
You can also query the sashelp.vtable to obtain the list of datasets:
proc sql;
create table mem_list as
select memname
from sashelp.vtable
where libname='LIB1' and memtype='DATA';
quit;