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
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;
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;
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.