BookmarkSubscribeRSS Feed
anandbillava
Fluorite | Level 6
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 ?
4 REPLIES 4
Cynthia_sas
SAS Super FREQ
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
anandbillava
Fluorite | Level 6
Hi Cynthia,
I am using XML mapper. It works fine if we do not use the XML map
Cynthia_sas
SAS Super FREQ
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
anandbillava
Fluorite | Level 6
I already posted it to tech support. Lets see what they have to say on it. Meanwhile I am keeping my try.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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