<?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 iterate through the records of a sas table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/iterate-through-the-records-of-a-sas-table/m-p/843498#M333473</link>
    <description>&lt;P&gt;I have a table in sas (see image) where I need to loop through each record to generate a json for each record (product).&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sateh_3-1668045639132.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77143i2361278388E4A082/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sateh_3-1668045639132.png" alt="sateh_3-1668045639132.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;each json generated must have the name of the product.&lt;/P&gt;&lt;P&gt;my code to generate my json is this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sateh_2-1668045523181.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77142iEDD2B921CCCC826E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sateh_2-1668045523181.png" alt="sateh_2-1668045523181.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I really don't know how I should do this. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Nov 2022 02:01:16 GMT</pubDate>
    <dc:creator>sateh</dc:creator>
    <dc:date>2022-11-10T02:01:16Z</dc:date>
    <item>
      <title>iterate through the records of a sas table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/iterate-through-the-records-of-a-sas-table/m-p/843498#M333473</link>
      <description>&lt;P&gt;I have a table in sas (see image) where I need to loop through each record to generate a json for each record (product).&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sateh_3-1668045639132.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77143i2361278388E4A082/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sateh_3-1668045639132.png" alt="sateh_3-1668045639132.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;each json generated must have the name of the product.&lt;/P&gt;&lt;P&gt;my code to generate my json is this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sateh_2-1668045523181.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77142iEDD2B921CCCC826E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sateh_2-1668045523181.png" alt="sateh_2-1668045523181.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I really don't know how I should do this. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2022 02:01:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/iterate-through-the-records-of-a-sas-table/m-p/843498#M333473</guid>
      <dc:creator>sateh</dc:creator>
      <dc:date>2022-11-10T02:01:16Z</dc:date>
    </item>
    <item>
      <title>Re: iterate through the records of a sas table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/iterate-through-the-records-of-a-sas-table/m-p/843514#M333477</link>
      <description>&lt;P&gt;I am not sure what you mean by "a json".&lt;/P&gt;
&lt;P&gt;If you want to generate a JSON file that has the information the dataset you took the selfie of then the code you posted the second selfie of looks reasonable.&lt;/P&gt;
&lt;P&gt;How is the resulting file different than what you wanted?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: If you want coding help post the data as DATA and not as PICTURES.&amp;nbsp; Also explain the output you want more clearly.&amp;nbsp; Proving the desired output for the example input data you share will go long way to help clarify your description of the desired results.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2022 03:58:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/iterate-through-the-records-of-a-sas-table/m-p/843514#M333477</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-10T03:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: iterate through the records of a sas table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/iterate-through-the-records-of-a-sas-table/m-p/843580#M333498</link>
      <description>&lt;P&gt;Yes, exactly what I need is a JSON file for each product, There should be 8 JSON files left because there are 8 products (records) in the table.&lt;BR /&gt;the result should be for example:&lt;BR /&gt;product_8085.json&lt;BR /&gt;product_8076.json&lt;BR /&gt;product_8087.json&lt;BR /&gt;product_8025.json&lt;BR /&gt;product_8060.json&lt;BR /&gt;product_8745.json&lt;BR /&gt;product_9528.json&lt;BR /&gt;product_6058.json&lt;BR /&gt;attached image of my data&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sateh_0-1668087004839.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77163i69814E5452CC9427/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sateh_0-1668087004839.png" alt="sateh_0-1668087004839.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2022 13:33:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/iterate-through-the-records-of-a-sas-table/m-p/843580#M333498</guid>
      <dc:creator>sateh</dc:creator>
      <dc:date>2022-11-10T13:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: iterate through the records of a sas table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/iterate-through-the-records-of-a-sas-table/m-p/843581#M333499</link>
      <description>&lt;P&gt;and what will be the content of the json files?&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2022 13:41:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/iterate-through-the-records-of-a-sas-table/m-p/843581#M333499</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-11-10T13:41:35Z</dc:date>
    </item>
    <item>
      <title>Re: iterate through the records of a sas table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/iterate-through-the-records-of-a-sas-table/m-p/843583#M333500</link>
      <description>&lt;P&gt;If you want to generate a lot of text files from a dataset (a JSON file is just a text file) then use a data step.&amp;nbsp; You can use the FILEVAR= option of the FILE statement to name a variable that will contain the name of the file to be written.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the general structure of your program could be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set myfile;
  length filename $200 ;
  filename = cats('product_',product,'.json');
  file json filevar=filename;
*   code here to write the json text using PUT statement ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your dataset only has the 3 or four variables you show in your photograph then the PUT statement to write JSON text will be trivial.&amp;nbsp; But you need to show an example of the JSON format you actually want to make.&amp;nbsp; And explain what parts of it need to come from the values of the variables in the dataset.&amp;nbsp; If the MYFILE dataset has multiple observations for the same product then you will probably need to make sure it is sorted and then you can use BY group processing in the dataset.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2022 13:59:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/iterate-through-the-records-of-a-sas-table/m-p/843583#M333500</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-10T13:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: iterate through the records of a sas table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/iterate-through-the-records-of-a-sas-table/m-p/843586#M333502</link>
      <description>&lt;P&gt;This is an example of how a JSON file of a single product should look like, in this case the first product 8085&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sateh_0-1668089704659.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77164i36CE614AB5EEF951/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sateh_0-1668089704659.png" alt="sateh_0-1668089704659.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2022 14:15:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/iterate-through-the-records-of-a-sas-table/m-p/843586#M333502</guid>
      <dc:creator>sateh</dc:creator>
      <dc:date>2022-11-10T14:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: iterate through the records of a sas table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/iterate-through-the-records-of-a-sas-table/m-p/843600#M333505</link>
      <description>&lt;P&gt;Post your data and code as text, retyping it is a pain in the ...;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically you can turn your small proc json into a macro and call it once for each line using CALL EXECUTE.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro create_json(producto=);
proc json out="/home/folder_json/producto_&amp;amp;producto..json" pretty nosastags;
export public.productos(where=id_producto=&amp;amp;producto).);
quit;

%mend;

*call macro for each line;
data _null_;
set public.productos;
str = catt('%create_json(producto=', id_producto, ');');
call execute(str);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/369041"&gt;@sateh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a table in sas (see image) where I need to loop through each record to generate a json for each record (product).&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sateh_3-1668045639132.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77143i2361278388E4A082/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sateh_3-1668045639132.png" alt="sateh_3-1668045639132.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;each json generated must have the name of the product.&lt;/P&gt;
&lt;P&gt;my code to generate my json is this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sateh_2-1668045523181.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77142iEDD2B921CCCC826E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sateh_2-1668045523181.png" alt="sateh_2-1668045523181.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I really don't know how I should do this. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2022 15:12:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/iterate-through-the-records-of-a-sas-table/m-p/843600#M333505</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-11-10T15:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: iterate through the records of a sas table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/iterate-through-the-records-of-a-sas-table/m-p/843620#M333518</link>
      <description>Thank you, this approach really helped me a lot.</description>
      <pubDate>Thu, 10 Nov 2022 16:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/iterate-through-the-records-of-a-sas-table/m-p/843620#M333518</guid>
      <dc:creator>sateh</dc:creator>
      <dc:date>2022-11-10T16:14:34Z</dc:date>
    </item>
  </channel>
</rss>

