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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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