Date: Thu, 30 Oct 2003 13:38:22 -0800
Reply-To: Lee Richardson <leepejean@YAHOO.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Lee Richardson <leepejean@YAHOO.COM>
Organization: http://groups.google.com
Subject: Re: Write Custom XML in 8.2
Content-Type: text/plain; charset=ISO-8859-1
Hi all,
I hadn't realized I was asking so much. I would be more comfortable
using a DOM kind of solution so I know my output is valid XML, and
thus my first inclination had been to go Java in the first place.
However those maintaining my application have SAS experience and no
Java experience and consiquently a hybrid solution, however
interesting, is probably out and put statements are in. Thank you all
for your input and Chang in particular for the code sample which will
be a big help to a SAS neophyte such as myself.
- Lee
chang_y_chung@HOTMAIL.COM (Chang Y. Chung) wrote in message news:<200310300345.h9U3jId22332@listserv.cc.uga.edu>...
> Hi, Lee,
>
> IMHO, the data step(put) method is not too ugly for this task. I
> respectively disagree with the java or document object model ideas, since
> it seems an over-kill for just converting a (by-)grouped sas data set into
> a tree (which is what an xml document really is).
>
> Having said that, I would love to hear about the "right" tasks to deligate
> to java DOM class(es) called from a SAS data step -- I also need
> justification to get my SAS upgraded to 9.1 (hopefully as soon as it is
> available!)
>
> <sasl:code>
> data one;
> input r1 r2 d $ @@;
> cards;
> 100 200 a 100 201 b 100 202 c
> 101 210 d 101 211 e
> ;
> run;
>
> proc sort data=one out=one_sorted;
> by r1 r2;
> run;
>
> data two;
> set one_sorted end=last;
> by r1 r2;
> file "~/two.xml";
> length row1 row2 data $12;
> row1 = trim(left(put(r1,best12.)));
> row2 = trim(left(put(r2,best12.)));
> data = trim(left(htmlencode(d)));
>
> if _n_ = 1 then put @1 "<example>";
> if first.r1 then put @3 "<outer_tag row=""" row1 +(-1) """>";
> if first.r2 then put @5 "<inner_tag row=""" row2 +(-1) """ " @;
> put "data=" """" data +(-1) """" @;
> if last.r2 then put "/>";
> if last.r1 then put @3 "</outer_tag>";
> if last then put @1 "</example>";
> run;
> </sasl:code>
>
> If your data have embedded single or double quotation marks, then quote
> them after calling htmlencode -- which quote only the first three of the
> famous (or notorious) five that should be quoted in xml.
>
> By the way, I would re-consider the xml document you are generating. One
> trivial reason is that it is not well-formed (there is one pair of opening
> and closing tags that do not match.) More substantially, I am not quite
> sure if it is a good idea to put both the lowest level (or group or class)
> value together with the data in the same tag as attributes. This seems to
> defeat the whole purpose of making it into a hierarchy. How about
> something more straight-forward like the following. Just a thought :-)
>
> <level0>
> <level1 value="100">
> <level2 value="201">a</level2>
> ...
> </level1>
> <level1 value="101">
> <level2 value="210">d</level2>
> ...
> </level1>
> </level0>
>
> Cheers,
> Chang
>
> On Wed, 29 Oct 2003 12:18:51 -0800, Lee Richardson <leepejean@YAHOO.COM>
> wrote:
>
> >Hi,
> >
> >I am new to SAS and am having difficulty figuring out how to write
> >custom XML given a dataset with hiearchial info. I was hoping for
> >something like the DOM where I can write a fairly complex nested XML
> >document. I have looked into the ODS MARKUP tag and have tried
> >writing my own tagset. The problem I ran into was that the most
> >granular event available in the "tagset language" seemed to be the
> >data event which catches everything. I am willing to resign myself to
> >writing the xml by hand with put statements, but this seems error
> >prone and generally ugly. I currently only have SAS 8.2 available,
> >but if this can only be done in 9.0 I can argue for an upgrade.
> >
> >Ultimately I want a dataset like:
> >100 200 a
> >100 201 b
> >100 202 c
> >101 210 d
> >101 211 e
> >
> >To look like:
> ><example>
> > <outer_tag row="100">
> > <inner_tag row="200" data="a"/>
> > <inner_tag row="201" data="b"/>
> > <inner_tag row="202" data="c"/>
> > </outer_data>
> > <outer_tag row="101">
> > <inner_tag row="210" data="d"/>
> > <inner_tag row="211" data="e"/>
> > </outer_tag>
> ></example>
> >
> >Thank you very much for your help.
> >
> > - Lee Richardson
|