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.
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.
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.
Thanks.
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!
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.