BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
vraj1
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
      
vraj1
Quartz | Level 8

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;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

sas-innovate-2024.png

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.

 

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
  • 3 replies
  • 993 views
  • 0 likes
  • 2 in conversation