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
- /
- Base SAS Programming
- /
- there is likely a proc for this but my thought is ...

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-28-2011 05:44 PM

I have observations for one variable and two additional variables representing two separate classes.

I would like to create a variable D, representing a ratio that relates an observation for variable var A in class B = 1 to observation for var A in class B = 0 given that A and B are in class C.

The data set might look something like:

varA varB varC

1 1 1

2 1 1

3 0 1

4 1 2

5 1 2

6 0 2

7 1 3

8 1 3

9 0 3

varD:

(1/3)

(2/3)

(4/6)

(5/6)

(7/9)

(8/9)

thanks much for any help

I would like to create a variable D, representing a ratio that relates an observation for variable var A in class B = 1 to observation for var A in class B = 0 given that A and B are in class C.

The data set might look something like:

varA varB varC

1 1 1

2 1 1

3 0 1

4 1 2

5 1 2

6 0 2

7 1 3

8 1 3

9 0 3

varD:

(1/3)

(2/3)

(4/6)

(5/6)

(7/9)

(8/9)

thanks much for any help

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

Posted in reply to jdub

03-28-2011 10:29 PM

[pre]

data temp;

input varA varB varC ;

datalines;

1 1 1

2 1 1

3 0 1

4 1 2

5 1 2

6 0 2

7 1 3

8 1 3

9 0 3

;

run;

data result(keep=vard);

merge temp(where=(varb eq 1) )

temp(rename=(vara=_vara varb=_varb) where=(_varb eq 0));

by varc;

vard=vara/_vara;

run;

[/pre]

Ksharp

data temp;

input varA varB varC ;

datalines;

1 1 1

2 1 1

3 0 1

4 1 2

5 1 2

6 0 2

7 1 3

8 1 3

9 0 3

;

run;

data result(keep=vard);

merge temp(where=(varb eq 1) )

temp(rename=(vara=_vara varb=_varb) where=(_varb eq 0));

by varc;

vard=vara/_vara;

run;

[/pre]

Ksharp

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

Posted in reply to jdub

03-29-2011 01:21 PM

Thanks much