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
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;
Why would you do this?
If you delete the part in red then the map does not match the output.
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.
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.
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
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.