Hi,
I have a longitudinal data on Patients with hypertension receiving a certain treatment. I would include the patient in the analysis , if and only if, he has two readings of blood pressure , one before treatment and one after. The data look like this
ID BloodPressure Time
1 110 Before
1 90 After
1 98 After
2 90 After
2 89 After
3 95 Before
3 97 After
4 100 before
4 98 Before
5 89 After
As you can see , Pateints number 2 and 4 Will not be included as they don't have readings before and after. Patient number 5 will also be deleted as he only have one reading
I only managed to delete cases with one reading using the command .
Data new ;
set Have;
By ID;
If FIRST.ID and LAST.ID then delete;
run;
Any suggestions ?
Use a SQL query:
data have;
input ID BloodPressure Time :$8.;
datalines;
1 110 Before
1 90 After
1 98 After
2 90 After
2 89 After
3 95 Before
3 97 After
4 100 before
4 98 Before
5 89 After
;
proc sql;
create table want as
select * from have
group by ID
having count(distinct upcase(time)) > 1;
select * from want;
quit;
Use a SQL query:
data have;
input ID BloodPressure Time :$8.;
datalines;
1 110 Before
1 90 After
1 98 After
2 90 After
2 89 After
3 95 Before
3 97 After
4 100 before
4 98 Before
5 89 After
;
proc sql;
create table want as
select * from have
group by ID
having count(distinct upcase(time)) > 1;
select * from want;
quit;
Thank you PG , I used it and it worked .
Be advised that the code that @PGStats provided counts levels not values. If for some reason you end up with something like Atfer, Bfeore or other spellings or words like missing then it well include those.
Yeah. I guess that counting DISTINCT UPCASE(FIRST(time)) would be a bit more robust.
I have done both of them and end with same results. I created the Time variable myself, so I would not expect to have misspellings or errors. However, it's a valuable advice , I will take it into consideration in other analyses.
Thank you
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!
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.
Ready to level-up your skills? Choose your own adventure.