BookmarkSubscribeRSS Feed
Anmolkhandelwal
Obsidian | Level 7

I have delimeted source file to be read in. there are some date fields with data such as given below.

dat1               dat2

11/14/2018 Nov 14 2
11/15/2018 Nov 15 2
11/15/2018 Nov 15 2

i need to read these values in format mmddyy10.

TIA

14 REPLIES 14
Kurt_Bremser
Super User

Please post the real contents of the file. Open it with an editor (not with Excel or similar!), and copy/paste the first few lines into a window opened with this button:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

 

Also show us your code, so we can tell you where you went wrong. Use the "little running man" right next to the button indicated above to post the code.

Anmolkhandelwal
Obsidian | Level 7
SVCDAT ENDDAT
11/14/2018 Nov 14 2
11/15/2018 Nov 15 2
11/15/2018 Nov 15 2
11/17/2018 Nov 17 2
here is my input data.
i have been able to read SVCDAT using mmddyy10. informat.
not able to read the enddat.
Kurt_Bremser
Super User

This is not a delimited file; unless the blank is the delimiter, which would mean it has 4 columns instead of 2.

Please read my post again on how to post the REAL contents of the file.

Anmolkhandelwal
Obsidian | Level 7
DATA sampledata;
     INPUT @6 svcdat mmddyy10. @15 endat mmddyy10.;
    CARDS;
     11/14/2018 nov 2 2;
  ;
RUN;

 Here is something i was trying, but the code for endata is completely wrong.

the enddat is present in my input in this type: 

Nov 14 2
Nov 15 2
Nov 15 2

i won't be able to add the source file data due to restrictions.

 

Kurt_Bremser
Super User

@Anmolkhandelwal wrote:

i won't be able to add the source file data due to restrictions.

 


Without seeing the original data in its raw form (with the real delimiters, and the real layout of the columns), it is impossible to help you.

It is also impossible to make a date out of this:

Nov 14 2

because "2" is not a valid year.

Anmolkhandelwal
Obsidian | Level 7

Anmolkhandelwal_0-1593076306991.png

Here is a screenshot of the input source file. the two dates are SVCDAT and ENDDAT.

if this may help.

Kurt_Bremser
Super User

And to which date should the string "Nov 14 2" translate? What would be the rule for the translation?

 

To me it seems that somewhere further up in the process a longer string was read into a default 8-character variable, causing truncation of values.

Anmolkhandelwal
Obsidian | Level 7
and to which date should the string "Nov 14 2" translate? What would be the rule for the translation?
AK: this date translate to enddat. the expected result is to read this date in mmddyy10. format.
Kurt_Bremser
Super User

@Anmolkhandelwal wrote:
and to which date should the string "Nov 14 2" translate? What would be the rule for the translation?
AK: this date translate to enddat. the expected result is to read this date in mmddyy10. format.

I did NOT ask for the NAME of the future variable, but for the VALUE that should come out of "Nov 14 2".

Anmolkhandelwal
Obsidian | Level 7
the value that is expected out of this date is: 11-14-2018.
andreas_lds
Jade | Level 19

@Kurt_Bremser wrote:

@Anmolkhandelwal wrote:
and to which date should the string "Nov 14 2" translate? What would be the rule for the translation?
AK: this date translate to enddat. the expected result is to read this date in mmddyy10. format.

I did NOT ask for the NAME of the future variable, but for the VALUE that should come out of "Nov 14 2".


Well, Kurt, obviously this means '14Nov2'd - or in yyyy-mm-dd: 2-11-14 🤓

Anything else would not make any sense at all or imply heavy guesswork.

Shmuel
Garnet | Level 18

@Anmolkhandelwal wrote:

Anmolkhandelwal_0-1593076306991.png

Here is a screenshot of the input source file. the two dates are SVCDAT and ENDDAT.

if this may help.


What is the origin to that input file?

Did you created it or did you got it from someone?

I have the filling that those dates having value like 'Nov 17 2' were truncated or

that those variables are concatenation of more then one variable.

 

Please check what is origin of those corrupted dates.

Shmuel
Garnet | Level 18

1) What code have you used to read those dates?

    Reading dat1 with mmddyy10. informat should result correctly.

    Have you defined a format to DAT1 ? (like ddmmyy10., mmddyy10., date9. etc.)

 

2) Dat2 seems to be truncated.
    Please copy paste few lines from the input file into </> icon.

 

3) In case of any issue it is very helpful to attach the log using the </> icon.

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
  • 14 replies
  • 1506 views
  • 0 likes
  • 4 in conversation