I have got below requirement
For the Same FormSeq
If T1TIMP = NOT NULL
THEN
the timepoint entered on T1TIMP should match with the timepoint entered on T2TIMP and T3TIMP for the same FormSeq. If not, then output.
What i am trying to do is writing multiple if then else condition which is getting really tedious, is there any efficient way to do this in one or two steps.
example dataset below:
data ndsn;
infile datalines;
input subjid $8. formseq T1TIMP $11. T2TIMP $15. T3TIMP $11.;
datalines;
ABCD123 1 PRE-DOSE 1.5HRS-POST 3HRS-POST
ABCD123 1 1.5HRS-POST 1.5HRS-POST 1.5HRPOST
ABCD123 1 1.5HRS-POST 3HRS-POST 1HRPOST
ABCD145 2 3.5HRS-POST 2HRS-POST 6HRPOST
ABCD168 2 2HRS-POST 6HRS-POST 8HRPOST
ABCD167 3 1.5HRS-POST 12HRS-POST 1HRPOST
ABCD167 3 1.5HRS-POST 3HRS-POST 2HRPOST
;
run;
any help please
The expected output should be as below, excluding the second row which is having all values matching for same formseq, sometimes they were not in one single row and i am trying to flag them if the values were not matching for the same formseq.
ABCD123 1 PRE-DOSE 1.5HRS-POST 3HRS-POST
ABCD123 1 1.5HRS-POST 3HRS-POST 1HRPOST
ABCD145 2 3.5HRS-POST 2HRS-POST 6HRPOST
ABCD168 2 2HRS-POST 6HRS-POST 8HRPOST
ABCD167 3 1.5HRS-POST 12HRS-POST 1HRPOST
ABCD167 3 1.5HRS-POST 3HRS-POST 2HRPOST
And what would be the expected output rom this example dataset? Please state for every result observation why it has to be included.
@Ravindra_ wrote:
I have got below requirement
For the Same FormSeq
If T1TIMP = NOT NULL
THEN
the timepoint entered on T1TIMP should match with the timepoint entered on T2TIMP and T3TIMP for the same FormSeq. If not, then output.
What i am trying to do is writing multiple if then else condition which is getting really tedious, is there any efficient way to do this in one or two steps.
example dataset below:
data ndsn; infile datalines; input subjid $8. formseq T1TIMP $11. T2TIMP $15. T3TIMP $11.; datalines; ABCD123 1 PRE-DOSE 1.5HRS-POST 3HRS-POST ABCD123 1 1.5HRS-POST 1.5HRS-POST 1.5HRPOST ABCD123 1 1.5HRS-POST 3HRS-POST 1HRPOST ABCD145 2 3.5HRS-POST 2HRS-POST 6HRPOST ABCD168 2 2HRS-POST 6HRS-POST 8HRPOST ABCD167 3 1.5HRS-POST 12HRS-POST 1HRPOST ABCD167 3 1.5HRS-POST 3HRS-POST 2HRPOST ; run;
any help please
See this:
data ndsn;
infile datalines;
input subjid $8. formseq T1TIMP $11. T2TIMP $15. T3TIMP $11.;
datalines;
ABCD123 1 PRE-DOSE 1.5HRS-POST 3HRS-POST
ABCD123 1 1.5HRS-POST 1.5HRS-POST 1.5HRS-POST
ABCD123 1 1.5HRS-POST 3HRS-POST 1HRPOST
ABCD145 2 3.5HRS-POST 2HRS-POST 6HRPOST
ABCD168 2 2HRS-POST 6HRS-POST 8HRPOST
ABCD167 3 1.5HRS-POST 12HRS-POST 1HRPOST
ABCD167 3 1.5HRS-POST 3HRS-POST 2HRPOST
;
data want;
set ndsn;
if not (T1TIMP = T2TIMP and T2TIMP = T3TIMP);
run;
Note that I had to edit the second observation of the source data.
By applying deMorgan's law, the code is a little simpler:
data want;
set ndsn;
if T1TIMP ne T2TIMP or T1TIMP ne T3TIMP;
run;
Might it not be better overall to transpose to a long format and sort with nodupkey? That would eliminate ALL duplicate values.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.