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

Hi. I'm new to SAS and I am trying to create a dataset with the following code:

 

data dtest;
input patient_id $
patient_name $;
format enttime time8.
draw1 time8.
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;

 

 

The code runs without any errors but when I check the created dataset, the variables enttime, draw1 and tdiff have missing values. 

I'm defining the time with time8 which is suppose to represent time in the hh:mm:ss format but it doesn't work. 

 

What am I doing wrong?

 

Thanks

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You have never given enttime draw and tdiff a value. You have not told SAS to read them in. You have only given them a format.

 

Something like this will work

 

data dtest;
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;

 

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

You have never given enttime draw and tdiff a value. You have not told SAS to read them in. You have only given them a format.

 

Something like this will work

 

data dtest;
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;

 

--
Paige Miller
ACLAN
Obsidian | Level 7
It works. Just a question: why do you use +1 in: input patient_id $ patient_name $ (enttime draw1 tdiff) (time8. +1);?
PaigeMiller
Diamond | Level 26

The +1 tells SAS to skip one character (in this case, a space between the different variables) and then start reading the next variable.

 

If you leave out the +1, you get NOTEs in the LOG, and you can see from what the LOG is saying that SAS is trying to read the last variable in the wrong columns.

--
Paige Miller

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