<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: proc json handling of empty values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-json-handling-of-empty-values/m-p/930927#M366262</link>
    <description>&lt;P&gt;If the logic in the macro works for you then you could always just remove/replace the linkages it has to other macros in that system.&amp;nbsp; Then tweak its inputs to match how your current system works.&amp;nbsp; Then you would only need to test that your modified macro performs in the same way and not need to re-test your other existing programs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From a quick glance it does appear to have thought about most of the issues involved in making JSON files (how to quote special characters etc.)&lt;/P&gt;</description>
    <pubDate>Wed, 05 Jun 2024 14:13:35 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-06-05T14:13:35Z</dc:date>
    <item>
      <title>proc json handling of empty values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-json-handling-of-empty-values/m-p/930851#M366223</link>
      <description>&lt;P&gt;I've created a json procedure that I've optimized and takes the fields as an parameter to the shared macro.&amp;nbsp; It's been working great, until today.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Today I learned that data may flow into this logic with NULL values.&amp;nbsp; However, the data get's passed as&amp;nbsp;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;addressLine1&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;&lt;SPAN&gt;"", instead of&amp;nbsp;"&lt;SPAN class=""&gt;addressLine1&lt;/SPAN&gt;"&lt;SPAN class=""&gt;: null.&amp;nbsp; Is there an option that I can add that will make this translation?&amp;nbsp; None of &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p0b4hbhs1jx9iln1jnda5ji2cupm.htm" target="_self"&gt;these&lt;/A&gt; appear to do the trick.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;		proc json out=request nopretty NOSASTAGS;
		   	write open object;
				write value &amp;amp;batch_object.;
			   	write open object;
					write values "batchID" "&amp;amp;batchID.";
					write value "batch";
				   	write open array;
			         	export jsonData&amp;amp;threadId. (keep= &amp;amp;json_keep_fields.);
				   	write close;
			   	write close;
		   	write close;
		run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2024 19:30:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-json-handling-of-empty-values/m-p/930851#M366223</guid>
      <dc:creator>noffer</dc:creator>
      <dc:date>2024-06-04T19:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: proc json handling of empty values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-json-handling-of-empty-values/m-p/930859#M366229</link>
      <description>&lt;P&gt;FWIW, I found this statement "By default, SAS writes an empty string ("") to the JSON output file when a SAS data set character variable contains a missing value." &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n1l8b4bgnxyfbzn1ry9ztq1ee7cv.htm" target="_self"&gt;here&lt;/A&gt;&amp;nbsp;which is somewhat confusing, considering the statement above. That says you can use the NULL keyword when using the write values statement.&amp;nbsp; So I have to do some crazy if/else statement to generate a null data element?&amp;nbsp; Seems hacky.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2024 20:26:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-json-handling-of-empty-values/m-p/930859#M366229</guid>
      <dc:creator>noffer</dc:creator>
      <dc:date>2024-06-04T20:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: proc json handling of empty values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-json-handling-of-empty-values/m-p/930872#M366233</link>
      <description>&lt;P&gt;I think they mean that it will write that empty quoted string for an empty character variable.&amp;nbsp; Which is consistent with how SAS treats such values.&amp;nbsp; In SAS character variables are fixed length and padded with spaces to fill out the full storage length.&amp;nbsp; So trailing spaces are meaningless.&amp;nbsp; And a character variable that is completely filled with only spaces is treated as MISSING.&amp;nbsp; So there is no difference between an empty string and a NULL value.&amp;nbsp; (Or for that matter between an empty string and a string of any length that is only spaces).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need the JSON text to have the keyword NULL instead then you will need to use a WRITE VALUE statement which is where the keyword NULL is part of the syntax (just like TRUE and FALSE are part of the syntax).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general I have found it much easier to just use a data step to write the JSON file.&amp;nbsp; Then you can control exactly what is written. And you can use BY group processing to help you generate any nested structures in the JSON structure you want to create.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2024 00:04:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-json-handling-of-empty-values/m-p/930872#M366233</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-05T00:04:09Z</dc:date>
    </item>
    <item>
      <title>Re: proc json handling of empty values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-json-handling-of-empty-values/m-p/930920#M366256</link>
      <description>&lt;P&gt;Thanks for the reply.&amp;nbsp; Its really quite unfortunate as empty numeric values look fine in the json.&amp;nbsp; I'm looking into this open source macro&amp;nbsp;&lt;A href="https://core.sasjs.io/mp__jsonout_8sas.html" target="_blank" rel="noopener"&gt;https://core.sasjs.io/mp__jsonout_8sas.html&lt;/A&gt;&amp;nbsp;, which may do the trick too, but now there's concerns about using "open source code", and we'll have to re-test a ton of work as a number of processes use the shared logic.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2024 14:16:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-json-handling-of-empty-values/m-p/930920#M366256</guid>
      <dc:creator>noffer</dc:creator>
      <dc:date>2024-06-05T14:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: proc json handling of empty values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-json-handling-of-empty-values/m-p/930927#M366262</link>
      <description>&lt;P&gt;If the logic in the macro works for you then you could always just remove/replace the linkages it has to other macros in that system.&amp;nbsp; Then tweak its inputs to match how your current system works.&amp;nbsp; Then you would only need to test that your modified macro performs in the same way and not need to re-test your other existing programs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From a quick glance it does appear to have thought about most of the issues involved in making JSON files (how to quote special characters etc.)&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2024 14:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-json-handling-of-empty-values/m-p/930927#M366262</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-05T14:13:35Z</dc:date>
    </item>
  </channel>
</rss>

