Learning SAS? Welcome to the exclusive online community for all SAS learners.

How can i read .dat file with the help of SAS code?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

How can i read .dat file with the help of SAS code?

I tried to extract or read .dat file in SAS Studio using SAS code but data is not coming in proper format,

Below is the code i have used to read .dat files.

* Create a SAS data set named toads;

* Read the data file ToadJump.dat using list input;

DATA toads;

  INFILE 'c:\MyRawData\ToadJump.dat';

  INPUT ToadName $ Weight Jump1 Jump2 Jump3;

RUN;

* Print the data to make sure the file was read correctly;

PROC PRINT DATA = toads;

  TITLE 'SAS Data Set Toads';

RUN;

But this doesn't seems to be perfect, can anyone help me with the solution?

Thanks in advance!


Accepted Solutions
Solution
‎09-07-2017 02:11 PM
Occasional Contributor
Posts: 9

Re: How can i read .dat file with the help of SAS code?

Hi, i got the answer to it but still thanks to all of you to reply on this.

View solution in original post


All Replies
Respected Advisor
Posts: 3,799

Re: How can i read .dat file with the help of SAS code?

The answer is in ToadJump.dat but we cannot see ToadJump.dat from way over here.

Occasional Contributor
Posts: 9

Re: How can i read .dat file with the help of SAS code?

Posted in reply to data_null__

ToadJump.dat is a data set, and i want to read the data available in ToadJump.dat data set through SAS, so the result should display on SAS.

But it's not displaying proper result, may be i am missing something in SAS code. Can you help me with the proper SAS code ?

Super User
Super User
Posts: 7,942

Re: How can i read .dat file with the help of SAS code?

When you say ToadJump is a dataset, what application created that dataset.  The file extension .dat doesn't actually mean anything, it just stands for data.  This would be text data, delimited data e.g. csv, Oracle dump file, XML etc. 

For instance, what happens if you right click -> open with -> Notepad

on the file?   Does it show nice text data, if so then write a datastep import program.

If it shows weird characters and such like, then it is a binary file, these are generally proprietary for instance old Excel files were proprietary format and then you need the application which created it, or some in between software.

So where does the data come from?

Occasional Contributor
Posts: 9

Re: How can i read .dat file with the help of SAS code?

This is text data

Super User
Posts: 19,770

Re: How can i read .dat file with the help of SAS code?

How is it not perfect?

What does your data look like?

Without knowing what the 'imperfections' are we can't help.

Occasional Contributor
Posts: 9

Re: How can i read .dat file with the help of SAS code?

After executing i get this data, i have attached image of data please find.Data Image.png

Solution
‎09-07-2017 02:11 PM
Occasional Contributor
Posts: 9

Re: How can i read .dat file with the help of SAS code?

Hi, i got the answer to it but still thanks to all of you to reply on this.

Super User
Super User
Posts: 7,039

Re: How can i read .dat file with the help of SAS code?

Looks like you could read the data, but perhaps it is not the types of numbers you expected?

You can just have the data step dump a few records of the source file to the log to see what it looks like.

DATA toads;

  INFILE 'c:\MyRawData\ToadJump.dat';

  INPUT ToadName $ Weight Jump1 Jump2 Jump3;

  if _n_ <= 10 then list ;

RUN;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 5763 views
  • 0 likes
  • 5 in conversation