I am trying to read date time column in my code. please find code below
data check;
input name $5. id 3. date datetime20. ;
FORMAT DATE DATETIME20. ;
DATALINES;
ROHAN 123 11AUG2020:19:17:20
MOHAN 123 11AUG2020:20:15:20
SOHAN 123 13AUG2020:00:17:20
KOHAN 123 15AUG2020:19:17:20
;
RUN;
I am getting missing value in particular date coloumn and even the id value is not being read properly
I am getting only first two didgit.
data check;
input name $5. id :3. date :datetime20. ;
FORMAT DATE DATETIME20. ;
DATALINES;
ROHAN 123 11AUG2020:19:17:20
MOHAN 123 11AUG2020:20:15:20
SOHAN 123 13AUG2020:00:17:20
KOHAN 123 15AUG2020:19:17:20
;
RUN;
Basically the idea is to read conveniently as a "modified list input" as opposed to using a in-formatted input.
data check;
input name $5. id :3. date :datetime20. ;
FORMAT DATE DATETIME20. ;
DATALINES;
ROHAN 123 11AUG2020:19:17:20
MOHAN 123 11AUG2020:20:15:20
SOHAN 123 13AUG2020:00:17:20
KOHAN 123 15AUG2020:19:17:20
;
RUN;
Basically the idea is to read conveniently as a "modified list input" as opposed to using a in-formatted input.
Use the colon modifier in your INPUT statement, or it will not honor the delimiters:
input name :$5. id :3. date :datetime20.;
You told the INPUT statement to read a fixed number of bytes for each variable. Just count the columns to see why it is not working.
----+---10----+---20----+---30 ROHAN 123 11AUG2020:19:17:20 MOHAN 123 11AUG2020:20:15:20 SOHAN 123 13AUG2020:00:17:20 KOHAN 123 15AUG2020:19:17:20
If the values are really always in fixed columns then adjust your INPUT statement to read from the right columns.
input @1 name $5. @7 id 3. @11 date datetime20. ;
Of if you know every line has three and only three space separated values and none of the values have embedded spaces then switch to list mode input instead of formatted mode.
input name :$5. id date :datetime20. ;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.