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

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  ?

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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;

PG

View solution in original post

5 REPLIES 5
PGStats
Opal | Level 21

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;

PG
Jordani
Obsidian | Level 7

Thank you PG , I used it and it worked .

ballardw
Super User

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.

PGStats
Opal | Level 21

Yeah. I guess that counting DISTINCT UPCASE(FIRST(time)) would be a bit more robust.

PG
Jordani
Obsidian | Level 7

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 

SAS Innovate 2025: Register Now

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!

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
  • 5 replies
  • 1771 views
  • 3 likes
  • 3 in conversation