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.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.