The correct syntax would be :
data persontime;
do i = 1 to 3;
input OC $ cases personyears;
select (OC);
when ("Current") do;
a1 = cases;
t1 = personyears;
end;
when ("Past") do;
a2 = cases;
t2 = personyears;
end;
when ("Never") do;
a3 = cases;
t3 = personyears;
end;
otherwise;
end;
end;
E1=t1/(t1+t2);
E2=t2/(t1+t2);
keep t1-t3 a1-a3 E1 E2;
datalines;
Current 13 4761
Past 164 121091
Never 113 98091
Never 114 98092
Current 12 4762
Past 165 121092
;
proc print data=persontime;
run;
OUTPUT occurs automatically each time execution reaches the end of the datastep (after reading three data lines). The datastep iterates until the end of input data is reached.
PG
i used that same method on this but it didnt work. im getting a table of 1s and 0s.
data crossoverdesign; | |
do i=2; | |
input subject group period1 period2; | |
dij=period1-period2; | |
select (dij); | |
when (1) do; | |
dij1=dij; | |
end; | |
when (2) do; | |
dij2=dij; | |
end; | |
otherwise; | |
end; | |
end; | |
datalines; | |
1 1 25 26 | |
2 1 47 38 | |
3 1 53 37 | |
4 2 48 35 | |
5 2 44 53 | |
6 2 45 44 | |
run; | |
proc means data=crossoverdesign noprint; | |
var dij1 dij2; | |
output out=sum (drop=_type_ _freq_) sum=sumdij1 sumdij2 n=n1 n2; | |
run; | |
proc print data=crossoverdesign; | |
run; | |
proc print data=sum; | |
run; | |
data en; | |
set sum; | |
dbar1= sumdij1/n1; | |
dbar2=sumdij2/n2; | |
dbar=0.5*(dbar1+dbar2); | |
run; | |
proc print data=en; |
run;
What did you want to get? Why using only cases where period1-period 2 is 1 or 2?
i wanted sas to find the difference in values dij between period1 and period 2 for each group. then, i need sas to give me the sum and the standard deviation of the differences for each group. so thats 2 different group values for the mean and std.
i thought these lines
when (1) do; | |
dij1=dij; | |
end; | |
when (2) do; | |
dij2=dij; | |
end; |
will give me separate differences for group 1 and 2
so what i want is dij1=period1-period2 for group 1 and dij2=period1-period2 for group2; then the mean and std of dij1 (for group1) and the mean and std of dij2 (for group2).
So, if that's all you want, I suggest you take this simple approach:
data crossoverdesign; | |
input subject group period1 period2; | |
datalines; | |
1 1 25 26 | |
2 1 47 38 | |
3 1 53 37 | |
4 2 48 35 | |
5 2 44 53 | |
6 2 45 44 |
;
proc sql;
create table groupStats as
select
group,
count(subject) as n,
mean(period1-period2) as mean12,
std(period1-period2) as std12
from crossoverdesign
group by group;
select * from groupStats;
quit;
Dataset groupStats will contain the statistics you want.
PG
THanks! You're awesome!
is there a way to output them separately though so that i can have a calculation like x=(n1-1)std1**2+(n2-1)std2**2... thats why i needed the output for each group to be separate.
Add a step to sum over the groups :
proc sql;
create table groupStats as
select
group,
count(subject) as n,
mean(period1-period2) as mean12,
std(period1-period2) as std12
from crossoverdesign
group by group;
create table stats as
select sum((n-1)*std12**2) as sumVar
from groupStats;
select * from stats;
quit;
PG
can you tell me why this isnt working tho. im just trying to try more things with it. im trying to find the mean and standard deviation of each period, subtract the means from each other and find the mean of that difference then subratct the standard deviations from each other. tried to google. thanks
data crossoverdesign;
input subject group period1 period2;
datalines;
1 1 25 26
2 1 47 38
3 1 53 37
4 2 48 35
5 2 44 53
6 2 45 44
;
proc sql;
create table groupStats as
select
group,
count(subject) as n,
mean(period1) as meanper1,
mean(period2) as meanper2,
std(period1) as stdper1,
std(period2) as stdper2,
mean(meanper1-meanper2) as dbar
from crossoverdesign
group by group;
create table stats as
select sum(n-1) as sumn,
sum(1/n) as expvar
from groupStats;
select * from stats;
quit;
data en;
set groupStats;
by group;
stdper=stdper1-stdper2;
run;
proc print data=en;
run;
create table groups as
select sum((n-1)*stdper**2) as sumVar
from groups;
select * from en;
quit;
Sdpooled=sqrt(sumVar)/sumn;
Sdbar=(Sdpooled/2)*(sqrt(expvar));
tstat=dbar/Sdbar;
tcrit=QUANTILE("T",0.95,sumn);
pvalue=2*(1 - probt(tstat,sumn));
LB=dbar-tcrit*Sdbar;
UB=dbar+tcrit*Sdbar;
run;
proc print data=en;
run;
i really am terrible at this. i just started learning SAS and there's so much to learn
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.