SAS proc ttest or proc mixed - sas

Hey so I'm trying to do a 2 tailed t test to well I'll just post the question
Solution 1: 9.9, 10.6, 9.4, 10.3, 10.0, 9.3, 10.3, 9.8
Solution 2: 10.2, 10.6, 10.0, 10.2, 10.7, 10.4, 10.5, 10.3
(a) Do the data indicate that the claim that both solutions have the same mean etch rate is valid? Use ( alpha= 0.05 and assume equal variances.
(b) Find a 95 percent confidence interval on the difference in mean etch rates.
Here is my code.
data one;
input one ##;
cards;
9.9 10.6 9.4 10.3 10.0 9.3 10.3 9.8
run;
data two;
input two ##;
cards;
10.2 10.6 10.0 10.2 10.7 10.4 10.5 10.3
run;
data one_two;
set one two;
run;
I have tried using proc t test however I am having a hard time making the 2 diffirent data sets compare with one another I was going to use Proc Mixed data however I am not getting any output with that. So any hints or tips that can be given will be very much appreciated.
Thanks.

Good day,
The issue seems to with the formatting. Code
data one_two;
set one two;
run;
Creates table like
one two
1 .
1 .
. 2
. 2
. 2
What you want to do is merge the data row by row:
data one_two;
merge one two;
run;
proc ttest data=one_two;
var one two;
run;
For more about merging in SAS see documentation.

Related

Specify a model with crossed and nested factors in sas proc mixed

Brief question
How do I write the model statement in proc mixed to study the interaction between a factor with a second factor nested within a third factor?
So factor_1 is independent from the others (like year is independent from location)
but factor_2 is a subdivision of factor_3 (like province is a subdivision of state).
I would expect it to be model factor_1 * factor_2(factor_3); but that does not work.
The real problem and context
I am trying to model this Crossed - Nested Design example from an Analysis of Variance and Design of Experiments course of Eberly College of Science using the techniques from this Nested Treatment Design example and the instructions given in this video.
Loading my data with
data PRODUCTION;
infile datalines dsd dlm='09'x;
array _M {6} _temporary_ (1 1 2 2 3 3);
array _C {6} _temporary_ (1 2 1 2 1 2);
array _O {6} _M1_C1 _M1_C2 _M2_C1 _M2_C2 _M3_C1 _M3_C2;
input Power _M1_C1 _M1_C2 _M2_C1 _M2_C2 _M3_C1 _M3_C2;
do _i = 1 to 6;
Machine = _M(_i);
Config = _C(_i);
Out_put = _O(_i);
output;
end;
drop _:;
datalines;
1 10.2 4.2 12.0 4.1 13.1 4.1
1 13.1 5.2 13.5 6.1 12.9 6.1
2 16.2 8.0 12.6 4.0 12.9 2.2
2 16.9 9.1 14.6 6.1 13.7 3.8
3 13.8 2.5 12.9 3.7 11.8 2.7
3 14.9 4.4 15.0 5.0 13.5 4.1
;run;
running this analysis
proc mixed data=PRODUCTION
method=type3
plots=all;
class Machine Config Power;
model Out_put =
Machine
Config(Machine)
Power
Machine*Power
Config(Machine)*Power;
store PRODUCTION;
run;
proc plm restore=PRODUCTION;
lsmeans Machine Config(Machine) Power
Power*Machine Power*Config(Machine)
/ adjust=tukey plot=meanplot cl lines;
ods exclude diffplot;
run;
I get this in the log
54 model Out_put =
55 Machine
56 Config(Machine)
2 The SAS System 08:31 Sunday, January 3, 2021
57 Power
58 Machine*Power
59 Config(Machine)*Power;
_
22
ERROR 22-322: Expecting a name.
60 store PRODUCTION;
ERROR: Variable NAME not found.
Distribute law wise
Config(Machine)*Power
might be one of these (of which model statement does accept)
Config(Machine*Power)
Power*Config(Machine)
The MODEL statement parses complex effects specifications according to algebraic expansion.
The SAS/STAT User's Guide section "Specification of Effects" bullet point for nested effects is
Nested effects are specified by following a main effect or crossed effect with a classification variable or list of classification variables enclosed in parentheses. The main effect or crossed effect is nested within the effects listed in parentheses: B(A) C(B*A) D*E(C*B*A). In this example, B(A) is read "B nested within A."NOTE: My bold. For me, things inside () are often concepted as the nested thing (deeper tier) within a hierarchy. So I might struggle here a little if I indeed need to mentally crossover concepts.
The SAS/STAT User's Guide section "Parameterization of PROC GLM Models" states
The GLM procedure constructs a linear model according to the specifications in the MODEL statement. Each effect generates one or more columns in a design matrix 𝕏. This section shows precisely how 𝕏 is built.
and discusses the process and design matrix created.

PROC MI not Returning matching results between 9.2 and 9.4

When running identical code between two versions of SAS (9.2 WIN and 9.4 Linux), I'm noticing that the results are differing between the two versions. Specifically imputed values are not matching.
I know that once in a while SAS likes to restructure PROCS and their options but I wasn't able to find any updates to this PROC in online documentation. Would anyone know if the syntax below is still valid in 9.4? Note the use of MONOTONE and predictive mean matching to impute missing values.
proc mi data=mitemp out=miout seed=37951 noprint nimpute=1;
class trt01pn coungr1n sexn;
Monotone regpmm;
VAR trt01pn coungr1n sexn ulc2 ulc3 ulc4 ulc5 ulc6 ulc7 ulc8 ulc9;;
by _imputation_;
run;

Boxplot in SAS using proc gchart

First question, is it possible to produce a boxplot using proc gchart in SAS?
If it is possible, please give me a brief idea.
Or else, on the topic of using proc boxplot.
Suppose I have a dataset that has three variables ID score year;
something like,
data aaa;
input id score year;
datalines;
1 50 2008
1 40 2007
2 30 2008
2 20 2007
;
run;
I want to produce a boxplot showing for each ID in each year. (So in this case, 4 boxplots in a single plot)
How can i achieve this?
I have tried using
proc boxplot data=aaa;
plot score*ID;
by year;
run;
However, this is not working as we can see year is not sorted by order.
Is there a way to get other this?
You need to sort your input dataset first. Run this
proc sort data = aaa;
by year;
run;
and then your proc boxplot should work as written.
This is quite easy to do with sgplot, which is part of the newer ODS Graphics suite which is available in base SAS.
proc sgplot data=sashelp.cars;
vbox mpg_city/category=type group=origin grouporder=ascending;
run;
You would use category=id and group=year in your example data - you get one separate tick on the x axis for each category and then you get a separate bar clustered together for each group.

Stacked bar chart by group and subgroup in SAS

I am unable to create stacked charts by group and subgroup in sas9.4, I want charts which are similar to excel graphs. Please find the sample data and excel graph below (first image) and also the SAS graph (second image).
I am unable to set the common year for the SEGMENT 'ACTUAL' AND 'FORECAST' on the same axis (year). The actual means the data has up to 2014 and forecast means after 2014, Both should fall in the same axis.
goptions reset=all ;
goptions colors=(red blue green);
legend1 label=none ;
proc gchart data=NEW;
vbar year/ discrete type=sum sumvar=VALUE
group= segment subgroup=WKSCOPE ;
where year le 2020 AND YEAR ge 2012;
run;
I would solve this with annotation. I know SGPLOT better than GCHART so I'll answer it this way.
data have;
input segment $ year wkscope $ value;
datalines;
ACTUAL 2012 PH 5
ACTUAL 2012 PH 1
ACTUAL 2012 BHS 1
ACTUAL 2012 RES 2
ACTUAL 2013 PH 2
ACTUAL 2013 PH 5
ACTUAL 2013 BHS 1
ACTUAL 2014 RES 2
FORECAST 2015 PH 3
FORECAST 2015 BHS 0
FORECAST 2016 PH 4
FORECAST 2016 RES 1
FORECAST 2017 PH 5
FORECAST 2017 BHS 1
FORECAST 2017 RES 2
;;;;
run;
data sgannods;
x1space='wallpercent';
y1space='wallpercent';
x1=75;
y1=-10;
label="Forecast";
function='text';
output;
x1=25;
label="Actual";
output;
run;
proc sgplot data=have sganno=sgannods;
vbar year/response=value group=wkscope groupdisplay=stack;
run;
Basically, do everything except segment, then annotate using that value. You can generate it by hand like I do, or (preferably) generate it from the original data if it could change. I use WALLPERCENT since it's going to be first half is actual last half is forecast, but if it could change (2 actual 4 forecast) then you shouldn't do that; you should either use WALLPERCENT and work out the proper position from the data (with a proc freq, probably) or use DATAVALUE and put it under the middle value.
If this isn't close enough, I would go to robslink.com, which has a nice set of examples (and is written by one of the developers of the GCHART set of procs). Sanjay also has a blog, Graphically Speaking which has some great examples, and both post on SAS Communities.
The image I produce follows here. It's not particularly close in other manners but all of those are easy to fix (color scheme, sizes, location of legends).
Data labels are the one thing you can't really have this way; they're addable if you use VBARPARM, but that requires summarizing the data ahead of time. Sanjay covers this in one of his blog posts about 9.4M2 (if you have the M2 maintenance release); I also cover this in my MWSUG Paper, Labelling without the Hassle: How to Produce Labeled Stacked Bar Charts Using
SGPLOT and GTL Without Annotate if you have an older version.

difference between proc univariate in sas 9.1 vs sas 9.3

In SAS 9.1, this code works fine and includes the missing values, which I need. As soon as I ported this program to SAS 9.3, it gave me the wrong minpoint values and excluded the missing values. How do I include the missing values and also why is it giving me the wrong output?
data myData;
input value;
datalines;
-2.47
-4
-5
5
6
7
8
9
10
12
;
run;
proc univariate data = myData noprint;
histogram value /
barwidth = 0.05
endpoints = (-2.5 to 2.45 by 0.05)
outhist = histogram
nochart;
run;
This is the HISTOGRAM dataset as output from SAS 9.1, which is correct:
MinPoint Cumpercent
-2.45 10%
-2.4 0%
-2.35 0%
However, in SAS 9.3 I get these results:
MinPoint Cumpercent
-2 10%
The first problem in the SAS 9.3 output is that observations with CUMPERCENT=0 are excluded. The second problem is that the minpoints are wrong.