DATA Step, Macro, Functions and more

split of number of subjects

Accepted Solution Solved
Reply
Regular Contributor
Posts: 161
Accepted Solution

split of number of subjects

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


Accepted Solutions
Solution
‎06-16-2016 07:16 AM
Super User
Super User
Posts: 7,988

Re: split of number of subjects

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;
      

View solution in original post


All Replies
Solution
‎06-16-2016 07:16 AM
Super User
Super User
Posts: 7,988

Re: split of number of subjects

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;
      
Regular Contributor
Posts: 161

Re: split of number of subjects

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;
Super User
Super User
Posts: 7,988

Re: split of number of subjects

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 246 views
  • 0 likes
  • 2 in conversation