Storing the PCT from proc gchart in a table - sas

I am using proc chart on a discrete variable.
I am curious how to store just the percentage value (pct) from the output into a table ?
I tried the gout option (gout=test1) below but it stores the whole graph as an image,
I dont want that. I just want the pct values.
proc gchart data= Native5 gout=test1;
hbar RBMI/discrete;
run;

Well, since the GOUT option was intended to output graphics, it would be a surprise if it did anything else. Just for the sake of interest, what version of SAS are you using? In 9.2 the GOUT option appears to be deprecated. Also, PROC GCHART is subsumed into PROC SGPANEL.
Is there a particular reason you want the relative frequencies from GCHART as opposed to TABULATE or FREQ?

Related

SAS-sgplot-add label to bar clusters

I am looking for an option to add label to bar clusters.
I want the values: 0.940, 0.250, 0.520, 0.580, and 0.230 in the middle of the clustered bars, like the following:
Assuming you have SAS 9.4 TS1M2 or later, you have an option, seglabel, which specifically does this, other than the 'display only once', which I don't think is a thing you can get out of the box.
proc sgplot data=sashelp.cars;
vbar cylinders/group=origin groupdisplay=cluster seglabel;
run;
If you don't, or you need more control than that gives you (such as your request to display only once), there are options, such as in my paper, Labelling without the hassle; it is for stacked bar charts, but the general approach would work for clustered also, you'd just have to adjust things some.
This gets somewhat close, and probably would get nearly perfect for your case; it needs some customization for groups that don't have all three group values present, but you don't have that in your example.
More complex solutions exist using annotations or GTL, as well, with this general approach (of overlaying on the precomputed bars a label).
proc summary data=sashelp.cars;
class origin cylinders;
types origin*cylinders;
var mpg_city;
output out=cars_summary(drop=_:) n(mpg_city)=count;
run;
data cars_labels;
set cars_summary;
if origin='Asia' then count_asia=count;
if origin='USA' then count_usa=count;
if origin='Europe' then count_eu=count;
ypos = floor(count/2);
run;
proc sgplot data=cars_labels;
vbarparm category=cylinders response=count/group=origin groupdisplay=cluster;
scatter x=cylinders y=ypos/markerchar=count_asia discreteoffset=-0.35;
scatter x=cylinders y=ypos/markerchar=count_usa discreteoffset=0.20;
scatter x=cylinders y=ypos/markerchar=count_eu discreteoffset=-0.1;
run;

Trying to remove confidence bands and prediction bands from SAS REG procedure

My code
proc reg data=mydata plots=;
title "Correlation Between Estriol Levels and Birthweights";
model birthweight=estriol / clb cli clm;
run;
Plots the regression line and scatter plot but also includes the confidence bands and prediction bands. Is there a way I can hide one, the other, or both from the REG output?
I don't believe there's a way within PROC REG but you can accomplish something similar using PROC SGPLOT. See the documentation here for specifics such as modifying the colour/style or doing multiple lines.
Here's an example that uses the SASHELP.CLASS data set as an example.
proc sgplot data=sashelp.class;
reg x=age y=height;
run;
Documentation:
http://support.sas.com/documentation/cdl/en/grstatproc/69716/HTML/default/viewer.htm#p0mn6vl6clqbgyn1ivs69lezdxhf.htm
By using plots=; you are requesting the default set of plots in the output. You probably want to suppress the default set using plots(only)= and then specifying only the graphics you want.
See the PROC REG statement options at http://support.sas.com/documentation/cdl/en/statug/66859/HTML/default/viewer.htm#statug_reg_syntax01.htm

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.

How do I create a pie chart in SAS for a variable whose values I've grouped using PROC FORMAT?

I have a variable ideology that takes on values from 1 to 7. I've decided to make these continuous values into three groups using PROC FORMAT like so:
proc format;
value ideofmt
1-2='Lib or Extr Lib'
3-5='Mod Lib, Slight Lib or Slight Cons'
6-7='Cons or Extr Cons';
run;
I want to create a pie chart that takes into account my grouping of these continuous values, if possible without having to modify the data itself. What I've tried is:
proc gchart data=sasuser.project2;
pie ideology /noheading percent=arrow slice=inside value=inside coutline=black
woutline=2;
format ideology ideofmt.;
run;
This gets me a pie chart that has the group labels that I want, but the pie chart is split into 7 slices (corresponding to the 7 values) instead of 3 (corresponding to the 3 groups).
Any help with this would be much appreciated. Thanks!
Add the discrete option to your pie statement:
proc gchart data=sasuser.project2;
pie ideology /noheading percent=arrow slice=inside value=inside coutline=black discrete
woutline=2;
format ideology ideofmt.;
run;
quit;
Otherwise, I think SAS assigns slices based on quantiles of your data, ignoring formatted values.
Also, a quit statement is required at the end of proc gchart in addition to the run statement.

how to find outliers in sas with proc means?

is there a way to detect an outlier from proc means while calculating min max Q1 and Q3?
the box plot procedure is not working on my SAS and I am trying to perform a boxplt in excel with the values from SAS.
Assuming you have a specific definition for what an outlier is, PROC UNIVARIATE can calculate the value that appears at that percentile using the PCTLPTS keyword on the OUTPUT statement. It also will identify extreme observations individually, so you can see the top few observations (if you have few enough observations that the number of extremes is likely to be <= 5).
The paper A SAS Application to Identify and Evaluate Outliers goes over a few of the ways you can look at outliers, including box plots and PROC UNIVARIATE, and includes some regression-based approaches as well.
If you want a 'standard boxplot' use the outbox= option in SAS to create the standard data set used for a box plot.
proc boxplot data=sashelp.class;
plot age*sex / outbox = xyz;
run;