BookmarkSubscribeRSS Feed
caesouza
Calcite | Level 5

Hello,

 

I´m trying to import data from .TXT file to dataset. The original data has the following format:

Original data from .TXTOriginal data from .TXT 

I´m using the following code:

DATA teste;
LENGTH
LOG_ID 8
LOG_DH_INICIO 8
LOG_DH_FIM 8
 LOG_ID_PROPOSTA 8

 

FORMAT
LOG_ID BEST18.
LOG_DH_INICIO DATETIME18.
LOG_DH_FIM DATETIME18.
LOG_NM_POLITICA $CHAR14.
LOG_ID_PROPOSTA BEST13.

 

INFORMAT
LOG_ID BEST18.
LOG_DH_INICIO DATETIME18.
LOG_DH_FIM DATETIME18.
LOG_ID_PROPOSTA BEST13.


INFILE 'xxxxxxxxxxxxxxxxx'
LRECL=32767
FIRSTOBS=2
OBS=11
ENCODING="LATIN1"
DLM='3b'x
MISSOVER
DSD ;

 

INPUT
LOG_ID : ?? BEST18.
LOG_DH_INICIO : ?? ANYDTDTM19.
LOG_DH_FIM : ?? ANYDTDTM19.
LOG_ID_PROPOSTA : ?? BEST13.

INFORMAT
LOG_ID BEST18.
LOG_DH_INICIO DATETIME18.
LOG_DH_FIM DATETIME18.
LOG_ID_PROPOSTA BEST13.

 

RUN;

 

The dataset result of this process is shown bellow, however the variables LOG_DH_INICIO and LOG_DH_FIM are in reverse comparing with the original ones. 

 image.png

 

How can I handle with this kind of error? SAS Log doesn´t show any error over this process.

3 REPLIES 3
Tom
Super User Tom
Super User

It is hard to tell from the photographs of the data but are those ID values more than 15 digits?  SAS cannot store more than 15 decimal digits exactly since it stores all numbers as 8 bytes floating point numbers.

 

You probably don't want to read ID variables as numbers. I really doubt that you are planning to take the mean of them or use them in a regression.

Reeza
Super User
What do you mean they're in reverse? They seem to be in the same order and same values, with a truncated ID in the first pic.

Also, you usually don't specify both format, informat and then specify those again in your INPUT statement. I would clean up the input statement to have only the list of variables.

Also, don't use excel to look at your text file, use a text editor otherwise you don't know what Excel has done to change how the file is displayed.
Tom
Super User Tom
Super User

If you use one of the ANYDT.... informats to read dates that are early in the month then it must guess whether it should use MDY or DMY order.  Which one it chooses is probably determined by some type of setting.

 

If you think that 11/06 means the 11th of June instead of November 6th then you should read the date value with DDMMYY informat and then your code will not depend on who runs it (or where they live).

 

Please show the actual lines from the text file (not a photograph of what it looks like after it has been read by a spreadsheet program) so we can see what the values actually look like. Use the Insert Code button in the editor to open a pop window that you can paste the lines into so that the spaces are not managed by the forum editor.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 701 views
  • 6 likes
  • 3 in conversation