DATA Step, Macro, Functions and more

Reading XML resulting dataset has datetime variable as missing value

Reply
Contributor
Posts: 72

Reading XML resulting dataset has datetime variable as missing value

I have writen a program for SAS to xml conversion and xml to sas conversion.
There is a variable which is datetime variable with format ddmmyy10.
Converstion of this dataset to xml works fine and the values stored as below
1943-12-11

But while reading back this XML to SAS dataset the datetime variables are converted as missing value.

libname out xml 'C:\temp.xml';

data out.temp;
set temp;
run;

Reading back to XML

libname in xml 'C:\temp.xml';
data temp;
set in.temp;
run;

The resulting dataset has datetime varialbe as missing values.


libname out xml 'C:\temp.xml';

It does work when i set the datetime variable to is8601da10 format while converting it to XML. Conversion back from XML does not require any change in code.

format xfer_date is8601da10.;


But I have lot of datasets and I am wrting a dynamic program which converts all the sas datasets at one shot to different xml files.
So I am not sure which are all the datetime formats there in the sas dataset.

Is there a way to set the sas date format globally to is8601da10 format.?
Or is there any better solution for this ?
SAS Super FREQ
Posts: 8,861

Re: Reading XML resulting dataset has datetime variable as missing value

Posted in reply to anandbillava
Hi:
When I create an XML file from a SAS dataset, like this:
[pre]
** make a SAS dataset with both date and datetime variables;
data bday;
infile datalines;
input name $ bdate : ddmmyy10. dtvar : datetime18.;
format bdate ddmmyy10.;
return;
datalines;
anne 15/11/1950 15nov1950:07:15:00
bob 23/08/1951 23aug1951:10:23:00
;
run;

** Create XML file FROM SAS data;
libname out xml 'C:\temp\outSAS.xml';

data out.bday;
set bday;
run;

libname out clear;
[/pre]

This is the XML output file that I get:
[pre]
<?xml version="1.0" encoding="windows-1252" ?>
<TABLE>
<BDAY>
<name> anne </name>
<bdate> 1950-11-15 </bdate>
<dtvar> -288031500 </dtvar>
</BDAY>
<BDAY>
<name> bob </name>
<bdate> 1951-08-23 </bdate>
<dtvar> -263741820 </dtvar>
</BDAY>
</TABLE>
[/pre]

When I use this code to READ the XML file back into a SAS dataset (without making any changes to the code):
[pre]
**Reading XML data back into SAS;

libname in xml 'C:\temp\outSAS.xml';
data work.bday_fromxml;
set in.bday;
run;

proc print data=work.bday_fromxml;
format bdate ddmmyy10. dtvar datetime18.;
run;

libname in clear;
[/pre]

This is my resulting PROC PRINT output (neither of my variables for date or datetime are missing):
[pre]
Obs DTVAR BDATE NAME

1 15NOV50:07:15:00 15/11/1950 anne
2 23AUG51:10:23:00 23/08/1951 bob

[/pre]

I ran the code in SAS 9.2...if you are having issues using the SAS XML Libname Engine, you might want to refer to the documentation. I believe that in SAS 8.2, you did need to have dates in ISO format, but that is no longer the case. I'm not sure when the date handling changed. You might with to work with Tech Support on this question. To open a track with Tech Support, go to:
http://support.sas.com/ctx/supportform/createForm

cynthia
Contributor
Posts: 72

Re: Reading XML resulting dataset has datetime variable as missing value

Posted in reply to Cynthia_sas
Hi Cynthia,
I am using XML mapper. It works fine if we do not use the XML map
SAS Super FREQ
Posts: 8,861

Re: Reading XML resulting dataset has datetime variable as missing value

Posted in reply to anandbillava
Hi:
You only need XML Mapper if your XML file is "non-standard" or heavily hierarchical or if you want to map the XML tags to particular column names (or vice versa) in SAS 9.2.

I would still recommend that you work with Tech Support on this question.

cynthia
Contributor
Posts: 72

Re: Reading XML resulting dataset has datetime variable as missing value

Posted in reply to Cynthia_sas
I already posted it to tech support. Lets see what they have to say on it. Meanwhile I am keeping my try.
Ask a Question
Discussion stats
  • 4 replies
  • 358 views
  • 0 likes
  • 2 in conversation