BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

Hello,

 

Here's the code I am using...

 

data class;

set sashelp.class;

if name="Jane" then do;

name=" Jane"; age = .;end;

run;

libname trans xml "\\...\Documents\Test\XML\test.xml" xmltype=oracle ;

data trans.class noprint;

set class;

run;

libname trans clear;

 

A part of my xml file looks like that:

 

<?xml version="1.0" encoding="windows-1252" ?>
<ROWSET>

.

.

.

<ROW>
      <Name> Jane</Name>
      <Sex>F</Sex>
      <Age missing="." />
      <Height>59.8</Height>
      <Weight>84.5</Weight>
   </ROW>

 

What I would like to get for missing value is:

 

<ROW>
      <Name> Jane</Name>
      <Sex>F</Sex>
      <Age></Age>
      <Height>59.8</Height>
      <Weight>84.5</Weight>
   </ROW>

 

I have look through the information on the web and I know that the use of tagset=tagset.sasxmiss could do the job.  Does some one know another tagset who will do the task.

 

 

This procedure below give me the tagset available on my system:

 

proc template;

list tagsets;

run;

 

 

 

Obviously, the tagset.sasxmiss is not present.  Is it possible to download this sasxmiss tagset or to update my tagsets?

 

Regards,

Where and how can I update my tagsets for SAS Enterprise Guide 7.11

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

Writing tagsets is a bit of an art, and I'm not that great at it.  But how about:

 

   proc template;
      define tagset tagsets.sasxnmis;
         parent = tagsets.sasxmog;
         notes "SAS-XML generic XML-Data - creates empty tag for MISSING";
      define event SASColumn;
      start:
         ndent;
         put     '<' ;
         put     NAME;
         put '>'      / if exists(missing);
         break;
      finish:
         put '</'       ;
         put NAME       ;
         put '>'  CR    ;
         xdent;
         break;
      end;
      define event MLEVDAT;
         break          / if exists(MISSING);
         put ' value="' / if cmp(XMLDATAFORM, "ATTRIBUTE");
         put VALUE      / if cmp(XMLDATAFORM, "ATTRIBUTE");
         put '"'        / if cmp(XMLDATAFORM, "ATTRIBUTE");
         break          / if cmp(XMLDATAFORM, "ATTRIBUTE");
         put '>'        ;
         put VALUE      ;
         break;
      end;
      end; /* sasxmiss */
   run;

   /*run this once (it will write to sasuser) and then to specify it */
   /*on the libname                                                  */

   libname foo xml 'c:\temp\nomiss.xml' tagset=tagsets.sasxnmis ;
   data foo.test; x=1; y=.; z=3; run;
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

View solution in original post

4 REPLIES 4
ChrisHemedinger
Community Manager

Are you looking for the approach in this example (Usage Note 23621: With the XML engine, how can I only output a node if it's not missing?)?

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
alepage
Barite | Level 11

hello Chris,

 

I have already tried this code and what it does, it erase the missing value element like that:

 

<?xml version="1.0" encoding="windows-1252" ?>
<TABLE>
   <TEST>
      <x>1</x>
      <z>3</z>
   </TEST>
</TABLE>

 

And what I would like is:

 

<?xml version="1.0" encoding="windows-1252" ?>
<TABLE>
   <TEST>
      <x>1</x>

       <y></y>
      <z>3</z>
   </TEST>
</TABLE>

 

Moreover, I will be very happy to write my own tagset.  If you could refer me a good document on the code use, it will be very appreciated.

ChrisHemedinger
Community Manager

Writing tagsets is a bit of an art, and I'm not that great at it.  But how about:

 

   proc template;
      define tagset tagsets.sasxnmis;
         parent = tagsets.sasxmog;
         notes "SAS-XML generic XML-Data - creates empty tag for MISSING";
      define event SASColumn;
      start:
         ndent;
         put     '<' ;
         put     NAME;
         put '>'      / if exists(missing);
         break;
      finish:
         put '</'       ;
         put NAME       ;
         put '>'  CR    ;
         xdent;
         break;
      end;
      define event MLEVDAT;
         break          / if exists(MISSING);
         put ' value="' / if cmp(XMLDATAFORM, "ATTRIBUTE");
         put VALUE      / if cmp(XMLDATAFORM, "ATTRIBUTE");
         put '"'        / if cmp(XMLDATAFORM, "ATTRIBUTE");
         break          / if cmp(XMLDATAFORM, "ATTRIBUTE");
         put '>'        ;
         put VALUE      ;
         break;
      end;
      end; /* sasxmiss */
   run;

   /*run this once (it will write to sasuser) and then to specify it */
   /*on the libname                                                  */

   libname foo xml 'c:\temp\nomiss.xml' tagset=tagsets.sasxnmis ;
   data foo.test; x=1; y=.; z=3; run;
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
alepage
Barite | Level 11

Thanks for your Help Chris!

It works

 

Unfortunately, I don't understand the code inside the proc template; Define tagset....

 

I found a paper nesug 2008.  I hope it will help how to write simple tagset...

regards,

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1838 views
  • 0 likes
  • 2 in conversation