I have dataset which has the following variables.
trial_id | main_treat | comparator1 | comparator2 | no_of_subj | split |
1 | aaa | inv | none | 234 | 1:1 |
2 | dsd | hfg | sfdg | 123 | 1:1:1 |
3 | aaa | dfs | none | 156 | 1:2 |
I need to replace main_treat and comp1 and comp2 with the split.
For ex for trial_id =1 it should have main_treat=234/2=117, comparator1=234/2=11 and comparator2=" ".
Can you help me in this how to do in efficient way
Hi,
I don't have access to SAS at the moment, so this is untested but (and note the reason this is so complicated is because of your data setup and having the ratio like that) :
data want; set have; array sp{3} 8.; do i=1 to countc(split,":")+1; sp{i}=input(scan(split,i,":"),best.); end; totsplit=sum(of sp{*}); main_treat=put((no_of_subj / totsplit) * sp{1},best.); comparator1=put((no_of_subj / totsplit) * sp{2},best.); comparator2=put((no_of_subj / totsplit) * sp{3},best.); run;
Hi,
I don't have access to SAS at the moment, so this is untested but (and note the reason this is so complicated is because of your data setup and having the ratio like that) :
data want; set have; array sp{3} 8.; do i=1 to countc(split,":")+1; sp{i}=input(scan(split,i,":"),best.); end; totsplit=sum(of sp{*}); main_treat=put((no_of_subj / totsplit) * sp{1},best.); comparator1=put((no_of_subj / totsplit) * sp{2},best.); comparator2=put((no_of_subj / totsplit) * sp{3},best.); run;
Further to the above code i also need to set up a condition. If condition=1 then split by 1:1(half) and if condition=2 then split equally.
example for cond 2 if the value is 42 then it should be 42 for all the 3 columns.
Can any one help how to do in this code.
data want; set have; array sp{3} 8.; do i=1 to countc(split,":")+1; sp{i}=input(scan(split,i,":"),best.); end; totsplit=sum(of sp{*}); main_treat=put((no_of_subj / totsplit) * sp{1},best.); comparator1=put((no_of_subj / totsplit) * sp{2},best.); comparator2=put((no_of_subj / totsplit) * sp{3},best.); run;
Hi,
It would be a good idea to start a new topic, posting test data (in the form of a datastep) and what the output should look like. Your logic isn't particularly clear to me, however it should just be a matter of putting an if <> statement around the sp{*} array.
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 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.