<?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: Edit an existing JSON file in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Edit-an-existing-JSON-file/m-p/830886#M82012</link>
    <description>&lt;P&gt;If I have my JSON in the following format:&lt;/P&gt;&lt;PRE&gt;{
   "parameters":{
      "type":"SEARCH_INDEX_LOADER",
      "filters":[
                        {
                                "type": "incrementalLoad",
                                "startTime": "2021-07-23T00:00:00.000Z"
                        }
      ]
   },
   "tasks":[
      {
         "parameters":{
            "type":"LOAD_DOCUMENT",
            "name":"EMPLEADO",&lt;BR /&gt;            "filters":[
                        {
                                "type": "incrementalLoad",
                                "startTime": "2021-07-23T00:00:00.000Z"
                        }
            ]
   },
   "tasks":[
      {
         "parameters":{
            "type":"LOAD_DOCUMENT",
            "name":"EMPLEADO"
         }
      },
      {
         "parameters":{
            "type":"LOAD_DOCUMENT",
            "name":"COMERCIO"
         }
      }

   ]
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;And let say I want to edit the &lt;STRONG&gt;startTime&lt;/STRONG&gt; under the second key i.e. &lt;STRONG&gt;tasks&lt;/STRONG&gt; keyword instead of the first &lt;STRONG&gt;startTime&lt;/STRONG&gt; under first &lt;STRONG&gt;parameters&lt;/STRONG&gt; key. Then is it possible to do so?&lt;/P&gt;</description>
    <pubDate>Mon, 29 Aug 2022 13:09:00 GMT</pubDate>
    <dc:creator>Vivi1997</dc:creator>
    <dc:date>2022-08-29T13:09:00Z</dc:date>
    <item>
      <title>Edit an existing JSON file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Edit-an-existing-JSON-file/m-p/756113#M80816</link>
      <description>&lt;P&gt;Hi there, I'm working with a JSON file that looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;{
   "parameters":{
      "type":"SEARCH_INDEX_LOADER",
      "filters":[
                        {
                                "type": "incrementalLoad",
                                "startTime": "2021-07-13T10:00:00.000Z"
                        }
      ]
   },
   "tasks":[
      {
         "parameters":{
            "type":"LOAD_DOCUMENT",
            "name":"EMPLEADO"
         }
      },      
      {
         "parameters":{
            "type":"LOAD_DOCUMENT",
            "name":"COMERCIO"
         }
      }

   ]
}&lt;/PRE&gt;&lt;P&gt;I'm looking for a way to change the&amp;nbsp;&lt;STRONG&gt;"startTime": "2021-07-13T10:00:00.000Z",&amp;nbsp;&lt;/STRONG&gt;with the current date time, the only way that might work is to create the JSON file from scratch with PROC JSON procedure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does someone know if there is a way to do that inside SAS?&lt;/P&gt;&lt;P&gt;(I'm trying to do a reincremental reindexing for SAS visual investigator)&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jul 2021 04:20:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Edit-an-existing-JSON-file/m-p/756113#M80816</guid>
      <dc:creator>valengvz</dc:creator>
      <dc:date>2021-07-23T04:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: Edit an existing JSON file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Edit-an-existing-JSON-file/m-p/756121#M80817</link>
      <description>&lt;P&gt;Well, this isn't using any of SAS's JSON functions or procedures, but the quick and dirty way to do it is with a Data step and simply swap out the value, 1 for 1.&amp;nbsp; In the below code, I'm reading from and writing to a SAS dataset for ease of demonstration.&amp;nbsp; In reality, you'd want to read from and write to a text file.&amp;nbsp; Note that in the results that the original date-time, 13 July..., has been replaced with the current date-time of my SAS server, 23 July...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Putlog statements are just there so it's easier to see what the code is doing; they're not essential to the final product of the program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	Have;
	INFILE	DATALINES	TRUNCOVER;
	INPUT
		Line_of_Data	$CHAR32767.;
DATALINES;
{
   "parameters":{
      "type":"SEARCH_INDEX_LOADER",
      "filters":[
                        {
                                "type": "incrementalLoad",
                                "startTime": "2021-07-13T10:00:00.000Z"
                        }
      ]
   },
   "tasks":[
      {
         "parameters":{
            "type":"LOAD_DOCUMENT",
            "name":"EMPLEADO"
         }
      },      
      {
         "parameters":{
            "type":"LOAD_DOCUMENT",
            "name":"COMERCIO"
         }
      }

   ]
}
;
RUN;

DATA	Want;
	KEEP	Line_of_Data;
	LENGTH	Time_Stamp	$128.;
	SET	Have;
	IF	INDEX(UPCASE(Line_of_Data), 'STARTTIME')	THEN
		DO;
			Start_Position	=	INDEX(UPCASE(Line_of_Data), 'STARTTIME') - 1;
			Time_Stamp		=	SCAN(Line_of_Data, 2, ' ');
			Stamp_Length	=	LENGTH(CAT('"startTime": ', Time_Stamp));
			PUTLOG	"NOTE:  Before "	Time_Stamp=;
			SAS_Time_Stamp	=	INPUT(COMPRESS(Time_Stamp,'"Zz'), ANYDTDTM20.);
			PUTLOG	"NOTE-  Before "	SAS_Time_Stamp=  SAS_Time_Stamp=	E8601DT23.3;
			PUTLOG	"NOTE-  ";
			SAS_Time_Stamp	=	DATETIME();
			PUTLOG	"NOTE-  After  "	SAS_Time_Stamp=  SAS_Time_Stamp=	E8601DT23.3;
			Time_Stamp		=	CATS('"', PUT(SAS_Time_Stamp, E8601DT23.3), 'Z"');
			PUTLOG	"NOTE-  After  "	Time_Stamp=;
			PUTLOG	"NOTE-  ";
			SUBSTR(Line_of_Data, Start_Position, Stamp_Length)	=	CAT('"startTime": ', Time_Stamp);
		END;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_1-1627020293499.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/61619i5D00B5F680BF6598/image-size/large?v=v2&amp;amp;px=999" role="button" title="jimbarbour_1-1627020293499.png" alt="jimbarbour_1-1627020293499.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jul 2021 06:05:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Edit-an-existing-JSON-file/m-p/756121#M80817</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-07-23T06:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: Edit an existing JSON file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Edit-an-existing-JSON-file/m-p/756215#M80818</link>
      <description>Thank you, I will start with this aproach.</description>
      <pubDate>Fri, 23 Jul 2021 14:36:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Edit-an-existing-JSON-file/m-p/756215#M80818</guid>
      <dc:creator>valengvz</dc:creator>
      <dc:date>2021-07-23T14:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: Edit an existing JSON file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Edit-an-existing-JSON-file/m-p/756268#M80819</link>
      <description>&lt;P&gt;Sounds good.&amp;nbsp; Please let me know if you encounter any problems, and let me know how it goes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jul 2021 17:15:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Edit-an-existing-JSON-file/m-p/756268#M80819</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-07-23T17:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: Edit an existing JSON file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Edit-an-existing-JSON-file/m-p/756274#M80820</link>
      <description>&lt;P&gt;Easy to read the data from the file. Then you can use the power of the INPUT and PUT statements.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile have dlm=':' dsd truncover ;
  file want;
  input name :$100. @ ;
  if name = 'startTime' then do;
    now = intnx('dtday',datetime(),0,'b');
    col = max(1,verify(_infile_,' '));
    put @col '"startTime": "' now E8601DT23.3 'Z"';
  end;
  else put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;{
   "parameters":{
      "type":"SEARCH_INDEX_LOADER",
      "filters":[
                        {
                                "type": "incrementalLoad",
                                "startTime": "2021-07-23T00:00:00.000Z"
                        }
      ]
   },
   "tasks":[
      {
         "parameters":{
            "type":"LOAD_DOCUMENT",
            "name":"EMPLEADO"
         }
      },
      {
         "parameters":{
            "type":"LOAD_DOCUMENT",
            "name":"COMERCIO"
         }
      }

   ]
}
&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Jul 2021 17:36:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Edit-an-existing-JSON-file/m-p/756274#M80820</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-23T17:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: Edit an existing JSON file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Edit-an-existing-JSON-file/m-p/830886#M82012</link>
      <description>&lt;P&gt;If I have my JSON in the following format:&lt;/P&gt;&lt;PRE&gt;{
   "parameters":{
      "type":"SEARCH_INDEX_LOADER",
      "filters":[
                        {
                                "type": "incrementalLoad",
                                "startTime": "2021-07-23T00:00:00.000Z"
                        }
      ]
   },
   "tasks":[
      {
         "parameters":{
            "type":"LOAD_DOCUMENT",
            "name":"EMPLEADO",&lt;BR /&gt;            "filters":[
                        {
                                "type": "incrementalLoad",
                                "startTime": "2021-07-23T00:00:00.000Z"
                        }
            ]
   },
   "tasks":[
      {
         "parameters":{
            "type":"LOAD_DOCUMENT",
            "name":"EMPLEADO"
         }
      },
      {
         "parameters":{
            "type":"LOAD_DOCUMENT",
            "name":"COMERCIO"
         }
      }

   ]
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;And let say I want to edit the &lt;STRONG&gt;startTime&lt;/STRONG&gt; under the second key i.e. &lt;STRONG&gt;tasks&lt;/STRONG&gt; keyword instead of the first &lt;STRONG&gt;startTime&lt;/STRONG&gt; under first &lt;STRONG&gt;parameters&lt;/STRONG&gt; key. Then is it possible to do so?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2022 13:09:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Edit-an-existing-JSON-file/m-p/830886#M82012</guid>
      <dc:creator>Vivi1997</dc:creator>
      <dc:date>2022-08-29T13:09:00Z</dc:date>
    </item>
  </channel>
</rss>

