Write and run SAS programs in your web browser

reading data in sas

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

reading data in sas

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.

 


Accepted Solutions
Solution
‎06-04-2016 04:45 AM
Super User
Posts: 11,134

Re: reading data in sas

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


All Replies
Super User
Posts: 9,874

Re: reading data in sas

What output would you like to see ?
Solution
‎06-04-2016 04:45 AM
Super User
Posts: 11,134

Re: reading data in sas

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.

Occasional Contributor
Posts: 12

Re: reading data in sas

Thanks.

New Contributor
Posts: 2

Re: reading data in sas

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
Super User
Posts: 11,134

Re: reading data in sas

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

☑ This topic is solved.

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

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