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

Hello all,

I have below data 

SUBArmScreenWeek1Week2Week3Week4Week5Week6Week7Week8Week9Week10TIME TO ACHIVE TARGET 10
1Test88.28.48.68.899.29.49.69.810.110
2Test8.78.99.19.39.59.79.910.110.310.510.77
3Ref99.29.49.69.81010.210.410.610.8115
4Test9.59.79.910.110.310.510.710.911.111.311.53
5Ref9.81010.210.410.610.81111.211.411.611.81
6Ref10.310.510.710.911.111.311.511.711.912.112.3-
7Test88.28.48.68.899.29.49.69.81010
8Ref9.29.49.69.81010.210.410.610.81111.24
9Ref8.68.899.29.49.69.81010.210.410.67
10Test8.38.58.78.99.19.39.59.79.910.110.39

 

i want to check that at which week subject has reached score of 10, in last column answer are there i want that column to be generated by coding if score is greater then 10 at screen we will drop that subject.

 

Thanks in advance.

 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

@jay_bhavsar wrote:
Hi friend,
may be i failed to explain the query i run the the code but its not giving answer as i accepted. let me explain you the situation.
SUB 1 reached to score of more then 10 at week10 so "Time to achieve target 10" has value 10.
Likewise SUB 1 reached to score of more then 10 at week7 so "Time to achieve target 10" has value 7.
and for sub 3 its week5, for sub 4 its week3, for sub 5 its week1, for sub 7 its week10, for 8 week4 and so on.
and what if all Column name is not in sequence (Ex: Jan Mar May Sep Dec) then how can we get values of time to achieve target 10.

There are no variables named "Jan", "Mar", etc in your data. Please post the data you have in usable form and with the variable names you have.

Please explain the role of the variables "Arm" and "Screen", are they necessary to calculate "TimeToAchieveTarget10"?

Untested:

data want;
  set have;
  length Target10 8;
  array values Week1-Week10;

  do i = 1 to dim(values);
    if values[i] >= 10 then do;
      Target10 = input(compress(vname(values[i]),,'kd'), 2.);
      leave;
    end;
  end;
run;

View solution in original post

14 REPLIES 14
PaigeMiller
Diamond | Level 26
/* UNTESTED CODE */
data want;
    set have;
    if screen>10 then delete;
    array w week1-week10;
    array ww _temporary_;
    do i = 1 to dim(w);
         ww(i)=(w(i)>=10);
    end;
    time_to_achieve_target_10 = whichn(1,of ww[*]);
    drop i;
run;

If you want tested code, please provide data as a SAS data set (instructions)

--
Paige Miller
jay_bhavsar
Obsidian | Level 7
Hi friend,
may be i failed to explain the query i run the the code but its not giving answer as i accepted. let me explain you the situation.
SUB 1 reached to score of more then 10 at week10 so "Time to achieve target 10" has value 10.
Likewise SUB 1 reached to score of more then 10 at week7 so "Time to achieve target 10" has value 7.
and for sub 3 its week5, for sub 4 its week3, for sub 5 its week1, for sub 7 its week10, for 8 week4 and so on.
and what if all Column name is not in sequence (Ex: Jan Mar May Sep Dec) then how can we get values of time to achieve target 10.
andreas_lds
Jade | Level 19

@jay_bhavsar wrote:
Hi friend,
may be i failed to explain the query i run the the code but its not giving answer as i accepted. let me explain you the situation.
SUB 1 reached to score of more then 10 at week10 so "Time to achieve target 10" has value 10.
Likewise SUB 1 reached to score of more then 10 at week7 so "Time to achieve target 10" has value 7.
and for sub 3 its week5, for sub 4 its week3, for sub 5 its week1, for sub 7 its week10, for 8 week4 and so on.
and what if all Column name is not in sequence (Ex: Jan Mar May Sep Dec) then how can we get values of time to achieve target 10.

There are no variables named "Jan", "Mar", etc in your data. Please post the data you have in usable form and with the variable names you have.

Please explain the role of the variables "Arm" and "Screen", are they necessary to calculate "TimeToAchieveTarget10"?

Untested:

data want;
  set have;
  length Target10 8;
  array values Week1-Week10;

  do i = 1 to dim(values);
    if values[i] >= 10 then do;
      Target10 = input(compress(vname(values[i]),,'kd'), 2.);
      leave;
    end;
  end;
run;
jay_bhavsar
Obsidian | Level 7

Thank you Andreas,

 

The code is giving desired results. One more thing to see what is some weeks in between are not there (file attached).

 variables  "Arm" and "Screen" is just for carry no need to check condition in that.

andreas_lds
Jade | Level 19

@jay_bhavsar wrote:

Thank you Andreas,

 

The code is giving desired results. One more thing to see what is some weeks in between are not there (file attached).

 variables  "Arm" and "Screen" is just for carry no need to check condition in that.


Sorry, but i won't open any office-file, please post the data in usable form.

jay_bhavsar
Obsidian | Level 7
which format is fine for you? SAS DATASET of any other??
PaigeMiller
Diamond | Level 26

Earlier, I gave a link to instructions to provide your data as SAS data step code. That's the best form to use.

--
Paige Miller
jay_bhavsar
Obsidian | Level 7

OK i am attaching file.

PaigeMiller
Diamond | Level 26

Many of us will not download files. The SAS code should be included in your reply, as text by pasting it into the window that appears when you click on the "running man" icon.

--
Paige Miller
jay_bhavsar
Obsidian | Level 7
data Have;
infile datalines ;
input SUB Arm $ Screen Week1 Week2 Week5 Week6 Week7 Week9 Week10 TIME_TO_ACHIVE_TARGET ;
datalines4;
1 Test 8 8.2 8.4 9 9.2 9.4 9.8 1 10
2 Test 8.7 8.9 9.1 9.7 9.9 1 5 7 7
3 Ref 9 9.2 9.4 10 2 4 8 11 5
4 Test 9.5 9.7 9.9 5 7 9 11.3 11.5 3
5 Ref 9.8 10 2 8 11 11.2 11.6 11.8 1
6 Ref 3 5 7 11.3 11.5 11.7 12.1 12.3 .
7 Test 8 8.2 8.4 9 9.2 9.4 9.8 10 10
8 Ref 9.2 9.4 9.6 2 4 6 11 11.2 4
9 Ref 8.6 8.8 9 9.6 9.8 10 4 6 7
10 Test 8.3 8.5 8.7 9.3 9.5 9.7 1 3 9
;;;;
PaigeMiller
Diamond | Level 26

This data is dramatically different than what you posted originally, and there are many places where the value is 1 whereas before it was 10, which of course changes the results. Are these typographical errors?

 

Could you please correct all of your data set (or inform me that it already is correct)? Could you please post the code in a code box as I requested?

--
Paige Miller
jay_bhavsar
Obsidian | Level 7

The posted data is same as before. the only difference is i removed some column to see how code can be apply when the sequence of Week1-Week10 is not there. 
As for all available columns the code provided previously is working perfectly. 

but i just curious to know what if we have columns which are not in sequence.

PaigeMiller
Diamond | Level 26

The posted data is same as before.

No it is not.

 

There were 10s in the original data set, and the value of 1 appears now. Are these typographical errors? If so, please correct them.

--
Paige Miller
andreas_lds
Jade | Level 19

Please explain why Time_To_Achieve_Target is 10 in the first line of the data you have posted. The maximum value is 9.8 in Week9.

 

The code i posted will need at one update if some week-variables don't exist. Changing the array-statement to

array values Week:;

should be sufficient, assuming that there are no variables in the dataset whose names start with "week" but must not considered in setting Time_To_Achieve_Target. And the variables must be properly sorted, if Week5 appears before Week4 the loop won't give the expected results.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 14 replies
  • 3997 views
  • 0 likes
  • 3 in conversation