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

I have got a requirement where i the variable is having multiple timepoints and they need to be in a sequence that were specified as per the specification and there are other two timepoint variables. here first i need to add a condition, if the sequence of first timepoint variable is not as per the order then the whole record must come in the output and also if the timepoint in either of the other  two variables(TP2, TP3) if it is not matching with the first one(TP1) then it should come in the output. I was able to achieve the second requirement but i am not able to find a solution for the first requirement. In the first requirement the sequence of TP1 variable should be (1,2,3,5,7,8,9,10,11) in this sequence 4 and 6 were missing as that will be present in other dataset. if this is not in sequence then it must be in output. Can someone please help.

example dataset

data ndsn;
infile datalines;
input subject visit $4. TP1 TP2 TP3;
datalines;
101 Day1 1  1  1
101 Day1 2  4  2
101 Day1 3  2  3
101 Day1 5  4  5
101 Day1 7  7  7
101 Day1 8  8  8
101 Day1 9  8  9
101 Day1 10 10 10
101 Day1 11 10 11
101 Day2 1  1  1
101 Day2 2  4  2
101 Day2 5  2  3
101 Day2 3  4  5
101 Day2 5  7  7
101 Day2 8  8  8
101 Day2 7  8  9
101 Day2 10 10 10
101 Day2 8 10 11
;
run;

desired output

data ndsn;
infile datalines;
input subject visit $4. TP1 TP2 TP3;
datalines;
101 Day1 2  4  2
101 Day1 3  2  3
101 Day1 5  4  5
101 Day1 9  8  9
101 Day1 11 10 11
101 Day2 2  4  2
101 Day2 5  2  3
101 Day2 3  4  5
101 Day2 5  7  7
101 Day2 7  8  9
101 Day2 8 10 11
;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
maguiremq
SAS Super FREQ

Use the RANGE function to detect if the results vary. If they don't, then remove them from the data set.

data want_mm (drop = flag);
	set have;
	if range(of tp1-tp3) = 0 then flag = "1";
		else flag = "0";
	if flag = "0" then output;
run;
Obs subject visit TP1 TP2 TP3 
1 101 Day1 2 4 2 
2 101 Day1 3 2 3 
3 101 Day1 5 4 5 
4 101 Day1 9 8 9 
5 101 Day1 11 10 11 
6 101 Day2 2 4 2 
7 101 Day2 5 2 3 
8 101 Day2 3 4 5 
9 101 Day2 5 7 7 
10 101 Day2 7 8 9 
11 101 Day2 8 10 11 

View solution in original post

2 REPLIES 2
maguiremq
SAS Super FREQ

Use the RANGE function to detect if the results vary. If they don't, then remove them from the data set.

data want_mm (drop = flag);
	set have;
	if range(of tp1-tp3) = 0 then flag = "1";
		else flag = "0";
	if flag = "0" then output;
run;
Obs subject visit TP1 TP2 TP3 
1 101 Day1 2 4 2 
2 101 Day1 3 2 3 
3 101 Day1 5 4 5 
4 101 Day1 9 8 9 
5 101 Day1 11 10 11 
6 101 Day2 2 4 2 
7 101 Day2 5 2 3 
8 101 Day2 3 4 5 
9 101 Day2 5 7 7 
10 101 Day2 7 8 9 
11 101 Day2 8 10 11 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 295 views
  • 1 like
  • 2 in conversation