BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
gnrslasher37
Fluorite | Level 6

how can i read the following data in .DAT file into sas.

 

02:05:00:104 20050103|OB_CHANGE|2_YEAR|912828DF4|1|20|ADD   |6|26D3918E86D75FF7|25558|20|A|20|20|

 

Thanks.

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Looks like data step and use DLM='|'.

If you want an actual datetime value you should read that first bit as character and then parse it for time and date bits.

 

Being occasionally lazy I might be tempted to use the import wizard on that file and then copy the generated code from the log and modify any missed details. Use a large value for the number of rows to guess, if practical the number of lines in the file.

Your first variable will most like be text as I doubt format is a standard datetime one SAS will recognize.

Parsing the date time bit would look something like:

time = input(scan(dtvariablename,1),time.);

date = input(scan(dtvaraiblename,2), yymmdd.);

and to get an actual datetime variable

datetime = dhms(date, 0,0,time);

You should apply appropriate formats to date, time and datetime suitable to your needs otherwise the values will be pretty meaningless to most humans looking at the data.

View solution in original post

5 REPLIES 5
Ksharp
Super User
What output would you like to see ?
ballardw
Super User

Looks like data step and use DLM='|'.

If you want an actual datetime value you should read that first bit as character and then parse it for time and date bits.

 

Being occasionally lazy I might be tempted to use the import wizard on that file and then copy the generated code from the log and modify any missed details. Use a large value for the number of rows to guess, if practical the number of lines in the file.

Your first variable will most like be text as I doubt format is a standard datetime one SAS will recognize.

Parsing the date time bit would look something like:

time = input(scan(dtvariablename,1),time.);

date = input(scan(dtvaraiblename,2), yymmdd.);

and to get an actual datetime variable

datetime = dhms(date, 0,0,time);

You should apply appropriate formats to date, time and datetime suitable to your needs otherwise the values will be pretty meaningless to most humans looking at the data.

gnrslasher37
Fluorite | Level 6

Thanks.

anoop1409
Calcite | Level 5

Here is the exact SAS code :

 

data work.datupld ;
infile "/home/anoopyuvaa0/xyz.dat" dlm='|';
length Timestamp $22;
input Timestamp $ var1 $ var2 $ var3 $ num1 num2 var4 $ num3 var5 $ num4 num5 var6 $ num6 num7;
run;
proc print data = work.datupld;
run;

Please see the attached screenshot for the output.

 

Thanks!


sascode.png
ballardw
Super User

Thank you for posting your exact solution.

 

For what it may be worth DAT is not any standard file structure. The contents can be a text and delimited as yours of proprietary binary. The first DAT files I ran into had the dat stand for "digital audio tape" and were for sound...

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1478 views
  • 0 likes
  • 4 in conversation