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

I'm having trouble figuring out how to hide an entire element on an xml output when there is no value. Here's an example;

 

<address_1>JOHN SMITH</address_1>

<address_3>555 SMITH STREET</address_3>

<address_4> </address_4>

 

I would like to address_4 to be hidden when there is no value. Here is what it looks like in my map;

 

        <COLUMN name="sbad_addr2_mail">
            <PATH syntax="XPath">/stmt/stmt_detail/generic_letter_1/send_address/address_4</PATH>
            <TYPE>character</TYPE>
            <DATATYPE>string</DATATYPE>
        </COLUMN>

Any help would be much appreciated.

 

Thanks,

Micah

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

An XML file is a flat text file. You can't hide anything. Either something is there and it's visible, or it's not there. There's no hiding.

So you apparently want to delete some lines in the text file.

To do that, read it in a data step after it's created, and remove all lines that have an unwanted value.

The step might look similar to this:

data _null_;

  infile XMLIN;

  file XMLOUT;

  input;

  if _infile_ ne '        <address_4> </address_4>';

  put _infile_;

run;

View solution in original post

5 REPLIES 5
ChrisNZ
Tourmaline | Level 20

Why would you do this?

If you delete the part in red then the map does not match the output.

micahmouw
Fluorite | Level 6

The output is the code block on top with the section highlighted in red. The vendor that I send the xml to requires that if the value is empty then the element should be hidden. There's a few other pieces of the map that would require this as well so understanding how to do it is extremely important.

ChrisNZ
Tourmaline | Level 20

I might be mistaken, but I am pretty sure that the structure must match the map.

 

The incomplete XML can still be read of course, but deleting (not hiding, deleting right?) entries because they have a certain value like space is bizarre.

 

SAS will not do this as far as I know. You'll have to do it post-export:

1- Generate the XML file

2- Read the text file in a data step and alter it however you like.

 

 

micahmouw
Fluorite | Level 6

Actually I'm just looking to hide the element. I'll try and explain it a little bit better. basically the data table will have, lets say, 100 records. I'll run the program to export it to SAS. 50 of the 100 records do not contain data for address_4. For those records that do not contain data for address_4 I would like to have the entire field hidden. Here's an example;

 

No value for address_4

       <send_address>
        <address_1>JOHN SMITH</address_1>
        <address_3>555 SMITH WAY</address_3>
        <city>SMITH</city>
        <state>CA</state>
        <zip>8675309</zip>
       </send_address>

 

Value present for address_4

 

       <send_address>
        <address_1>JOHNETTE SMITH</address_1>
        <address_3>555 JOHNETTE ST</address_3>
        <address_4>APARTMENT A</address_4>
        <city>SMITH</city>
        <state>CA</state>
        <zip>8675309</zip>
       </send_address>

 

I hope this makes sense. I would think it would be possible at least I really hope it is. Thanks for the feedback so far.

 

-Micah

 

ChrisNZ
Tourmaline | Level 20

An XML file is a flat text file. You can't hide anything. Either something is there and it's visible, or it's not there. There's no hiding.

So you apparently want to delete some lines in the text file.

To do that, read it in a data step after it's created, and remove all lines that have an unwanted value.

The step might look similar to this:

data _null_;

  infile XMLIN;

  file XMLOUT;

  input;

  if _infile_ ne '        <address_4> </address_4>';

  put _infile_;

run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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