BookmarkSubscribeRSS Feed
jdub
Calcite | Level 5
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
2 REPLIES 2
Ksharp
Super User
[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

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 649 views
  • 0 likes
  • 2 in conversation