BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aexor
Lapis Lazuli | Level 10

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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. 

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20
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. 

Aexor
Lapis Lazuli | Level 10
Thanks 🙂
Tom
Super User Tom
Super User

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. ;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 703 views
  • 3 likes
  • 4 in conversation