turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Re: IF then output statement

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-20-2014 10:02 PM

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

PG

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-22-2014 12:31 PM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-22-2014 02:40 PM

What did you want to get? Why using only cases where period1-period 2 is 1 or 2?

PG

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-22-2014 02:58 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-22-2014 03:02 PM

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).

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-22-2014 04:54 PM

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

PG

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-22-2014 05:11 PM

THanks! You're awesome!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-22-2014 07:09 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-22-2014 08:54 PM

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

PG

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-24-2014 01:30 PM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-22-2014 03:03 PM

i really am terrible at this. i just started learning SAS and there's so much to learn