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