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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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