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

I'm trying to correct the values in a specific columns for rows in which a specific condition is found.

Using the following dataset as example:

 

data dttest;

input patient_id $ patient_name $ (enttime draw1 tdiff) (time8. +1);

format enttime draw1 tdiff time8.;

datalines;

18C020 Garcia 11:45:00 11:50:00 00:07:00

17C222 Gibson 11:43:00 11:47:00 00:04:00

18C023 Knapp 11:42:00 11:45:00 00:43:00

10C032 Mueller 09:11:00 11:47:00 02:36:00

;

run;

 

For the rows where patient_id has "18C", I would like to correct the values in column tdiff by subtracting the time in colum draw1 from the time in column enttime.

 

I have tried IF/THEN and WHERE to select the rows but I always have an error. Not sure if it is a good idea to create an array.  

 

Anyone has a simple solution for this?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Please try

 

data dttest;
input patient_id $ patient_name $ (enttime draw1 tdiff) (time8. +1);
format enttime draw1 tdiff time8.;
datalines;
18C020 Garcia 11:45:00 11:50:00 00:07:00
17C222 Gibson 11:43:00 11:47:00 00:04:00
18C023 Knapp 11:42:00 11:45:00 00:43:00
10C032 Mueller 09:11:00 11:47:00 02:36:00
;
run;

data want;
set dttest;
if index(patient_id,'18C') then tdiff=draw1-enttime;
format tdiff time8.;
run;
Thanks,
Jag

View solution in original post

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16

Please try

 

data dttest;
input patient_id $ patient_name $ (enttime draw1 tdiff) (time8. +1);
format enttime draw1 tdiff time8.;
datalines;
18C020 Garcia 11:45:00 11:50:00 00:07:00
17C222 Gibson 11:43:00 11:47:00 00:04:00
18C023 Knapp 11:42:00 11:45:00 00:43:00
10C032 Mueller 09:11:00 11:47:00 02:36:00
;
run;

data want;
set dttest;
if index(patient_id,'18C') then tdiff=draw1-enttime;
format tdiff time8.;
run;
Thanks,
Jag
ACLAN
Obsidian | Level 7
It works thanks. I forgot to define the format

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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