<?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: Reading data from JSON as charcater in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/873011#M344937</link>
    <description>&lt;P&gt;The problem it mainly creates is that you will probably need to examine every file to make sure you know the full set of possible variables can occur in that particular type of file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example you might want to loop over all of the files and generate a complete list of the variables.&lt;/P&gt;
&lt;P&gt;You could use something like this:&lt;/P&gt;
&lt;P&gt;1) Get a list of all of the JSON files into a dataset, Call it FILES with a variable names FILENAME.&lt;/P&gt;
&lt;P&gt;2) Use that file to generate code that makes a libref and finds the variable names and max length and aggregates that into a single dataset.&lt;/P&gt;
&lt;P&gt;3) then use that dataset to generate the best estimate for the LENGTH of the character variables so you can use it to make the MAP file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If we assume that the text before the first _ in the filename defines which of the 23 groups then you might make a macro like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro check_names(filename);
libname json "&amp;amp;filename";
proc sql ;
create table check_one as
  select scan("&amp;amp;filename",-1,'/\') as filename length=200
       , scan(calculated filename,1,'_') as group length=20 
       , p1 as NAME length=32
       , count(*) as N
       , max(length(value)) as LENGTH
  from json.alldata
  group by 1,2,3
;
quit;
libname json clear;
proc append base=check_names data=check_one force;
run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then call it once for each file you have.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_:
  set files;
  call execute(cats('%nrstr(%check_name)(',filename,')'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you could get the list of variables per group from that aggregated summaries.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table group_variables as
select group
     , name
     , count(*) as n_files
     , sum(n) as n
     , max(length) as length
 from check_names
group by 1,2
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 29 Apr 2023 21:49:43 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-04-29T21:49:43Z</dc:date>
    <item>
      <title>Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872442#M344699</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;Is there any simple option to read all data from JSON file as character using JSON libname engine?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 05:56:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872442#M344699</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-04-27T05:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872563#M344727</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/437116"&gt;@BayzidurRahman&lt;/a&gt;&amp;nbsp;I suggest you check the&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_038/lestmtsglobal/n1jfdetszx99ban1rl4zll6tej7j.htm?fromDefault=" target="_self"&gt;LIBNAME Statement: JSON Engine&lt;/A&gt;&amp;nbsp;documentation and the&amp;nbsp;ALLDATA= "name"&amp;nbsp;LIBNAME Option&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;H4 class="xisDoc-argument"&gt;ALLDATA= "&lt;EM class="xisDoc-userSuppliedValue"&gt;name&lt;/EM&gt;"&lt;/H4&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;renames the ALLDATA data set to the specified name. &lt;FONT color="#FF6600"&gt;A data set named ALLDATA is created by default when the JSON engine runs.&lt;/FONT&gt; The ALLDATA data set contains all of the information in the JSON file. This option creates the data set with the specified name instead. The new name must meet the conventions for SAS names.&lt;/P&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Thu, 27 Apr 2023 12:55:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872563#M344727</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2023-04-27T12:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872738#M344794</link>
      <description>&lt;P&gt;May be my question was not clear enough. I don't have any issue with the data name.&lt;/P&gt;&lt;P&gt;I want to import all the variables from a JASON file as character variables.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 06:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872738#M344794</guid>
      <dc:creator>bayzid</dc:creator>
      <dc:date>2023-04-28T06:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872807#M344820</link>
      <description>&lt;P&gt;You need to be more specific about what you need.&amp;nbsp; A JSON file can have a very complex structure, so a general solution that works for ANY JSON file would be extremely complex.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To do the general solution I would recommend taking the following approach.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Use the JSON engine with AUTOMAP feature to have SAS make a GUESS at how to structure the resulting dataset(s).&lt;/LI&gt;
&lt;LI&gt;Use the JSON engine to convert the MAP file generated (the MAP file is itself a JSON file).&lt;/LI&gt;
&lt;LI&gt;Modify the datasets generated in step2 so that all of the variables are now character.&lt;/LI&gt;
&lt;LI&gt;Use the modified dataset to create a new MAP file.&lt;/LI&gt;
&lt;LI&gt;Use the modified MAP file to read the original JSON file.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Fri, 28 Apr 2023 14:06:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872807#M344820</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-28T14:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872813#M344822</link>
      <description>&lt;P&gt;My JASON file has very simple structure as follows. A sample code would be highly appreciated.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="bayzid_0-1682691163412.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83376i6D60D85369BE289F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="bayzid_0-1682691163412.png" alt="bayzid_0-1682691163412.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 14:12:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872813#M344822</guid>
      <dc:creator>bayzid</dc:creator>
      <dc:date>2023-04-28T14:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872820#M344826</link>
      <description>&lt;P&gt;If every line has the same four variables then just read it like it was a text file.&lt;/P&gt;
&lt;P&gt;Remember to adjust for the goofy way JSON handles quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example that assumes the strings are always NAME:VALUE and that they always have the same four variables in the same order.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile 'myfile.json' dsd dlm='{[,:]}' truncover ;
  row+1;
  input @;
  _infile_=tranwrd(_infile_,'\\','00'x);
  _infile_=tranwrd(_infile_,'\"','""');
  _infile_=tranwrd(_infile_,'00'x,'\');
  input (4*var1  2*var2 2*var3 2*var4) (:$200.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that fails because it is not so regular then go back to the code from your other question that reads the lines into NAME/VALUE pairs.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 14:24:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872820#M344826</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-28T14:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872831#M344834</link>
      <description>&lt;P&gt;The problem with the other code of Name/Value pair is that some of the concatenated tables are very large (~1billion observations in wide format), although my machine has enough power, for such big files it is always losing some data.&lt;BR /&gt;The other alternative is to convert individual JSON files into SAS file where all the variables are character and then append those SAS files using data step with wildcard after file name.&lt;BR /&gt;I have been using a macro loop to convert the individual JSON files into SAS file using the following code. Now I am looking for some options there so that it converts all the variables as character.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/*Import the json files one by one from the directory and creating a dataset in the Work library*/ 
%macro importjson;                                                   
   %do i=1 %to &amp;amp;nobs;                                               
      libname test JSON "C:\Users\mq10004085\Macquarie University\MRFF Aged care Data - Documents\JSON_1st_02032023\&amp;amp;&amp;amp;file&amp;amp;i...json" ORDINALCOUNT= NONE ;*NOALLDATA; 
data sas.&amp;amp;&amp;amp;ds&amp;amp;i ; /*Creating tables in the Work library instead of the samt lib*/
set test.Root;
dataname="&amp;amp;&amp;amp;file&amp;amp;i"; /*Variable containing the json file names*/
Phid="&amp;amp;i"; /*Phid containing the index*/
run;                                                 
%end;                                                               
%mend importjson;                                                                                                                            
%importjson ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Apr 2023 14:35:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872831#M344834</guid>
      <dc:creator>bayzid</dc:creator>
      <dc:date>2023-04-28T14:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872834#M344837</link>
      <description>&lt;P&gt;Sorry to sound like broken record.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Create a MAP file that reads the JSON files the way you want.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then modify your macro to use that map file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname test JSON "C:\Users\mq10004085\Macquarie University\MRFF Aged care Data - Documents\JSON_1st_02032023\&amp;amp;&amp;amp;file&amp;amp;i...json" 
  ORDINALCOUNT= NONE 
  MAP="C:\Users\mq10004085\Macquarie University\myjson.map"
;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Apr 2023 14:41:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872834#M344837</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-28T14:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872837#M344840</link>
      <description>&lt;P&gt;Sorry for not understanding your point. This is because I have very limited knowledge about map file.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 14:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872837#M344840</guid>
      <dc:creator>bayzid</dc:creator>
      <dc:date>2023-04-28T14:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872840#M344843</link>
      <description>&lt;P&gt;They are just text files.&amp;nbsp; You can edit them by hand if you want.&lt;/P&gt;
&lt;P&gt;Make sure to switch form the CURRENT_LENGTH field that the automap generates to the more rigid LENGTH field.&amp;nbsp; Otherwise you will still get individual datasets with different length character variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run this code to see an example of a MAP file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename json temp;
proc json out=json;
   export sashelp.class;
run;

filename map temp;
libname json json map=map automap=reuse;

data _null_;
  infile map;
  input;
  put _infile_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;{
  "DATASETS": [
    {
      "DSNAME": "root",
      "TABLEPATH": "/root",
      "VARIABLES": [
        {
          "NAME": "ordinal_root",
          "TYPE": "ORDINAL",
          "PATH": "/root"
        },
        {
          "NAME": "SASJSONExport",
          "TYPE": "CHARACTER",
          "PATH": "/root/SASJSONExport",
          "CURRENT_LENGTH": 3
        }
      ]
    },
    {
      "DSNAME": "SASTableData_CLASS",
      "TABLEPATH": "/root/SASTableData+CLASS",
      "VARIABLES": [
        {
          "NAME": "ordinal_root",
          "TYPE": "ORDINAL",
          "PATH": "/root"
        },
        {
          "NAME": "ordinal_SASTableData_CLASS",
          "TYPE": "ORDINAL",
          "PATH": "/root/SASTableData+CLASS"
        },
        {
          "NAME": "Name",
          "TYPE": "CHARACTER",
          "PATH": "/root/SASTableData+CLASS/Name",
          "CURRENT_LENGTH": 7
        },
        {
          "NAME": "Sex",
          "TYPE": "CHARACTER",
          "PATH": "/root/SASTableData+CLASS/Sex",
          "CURRENT_LENGTH": 1
        },
        {
          "NAME": "Age",
          "TYPE": "NUMERIC",
          "PATH": "/root/SASTableData+CLASS/Age"
        },
        {
          "NAME": "Height",
          "TYPE": "NUMERIC",
          "PATH": "/root/SASTableData+CLASS/Height"
        },
        {
          "NAME": "Weight",
          "TYPE": "NUMERIC",
          "PATH": "/root/SASTableData+CLASS/Weight"
        }
      ]
    }
  ]
}
&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Apr 2023 15:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872840#M344843</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-28T15:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872843#M344845</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/108705"&gt;@bayzid&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Sorry for not understanding your point. This is because I have very limited knowledge about map file.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The documentation has a good explanation, as well as an example of creating a map from a json file, and then editing it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsglobal/n1jfdetszx99ban1rl4zll6tej7j.htm#p1bwa176ppg0ydn135d8wl01vdcm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsglobal/n1jfdetszx99ban1rl4zll6tej7j.htm#p1bwa176ppg0ydn135d8wl01vdcm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The map has the metadata to define the SAS variables type, length, label, etc, in the same way as you would use an the informat statement, length statement, label statement, etc if you were reading it by hand.&lt;BR /&gt;&lt;BR /&gt;An alternative approach would be to read the data and let some fields come in as numeric variables.&amp;nbsp; Then in a separate step you could convert all the numeric fields to character (and enforce a standard length).&amp;nbsp; But the map approach is cleaner.&amp;nbsp; If someone was kind enough to give you a data dictionary, you could use that to build the map file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 15:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872843#M344845</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-04-28T15:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872844#M344846</link>
      <description>Thanks.&lt;BR /&gt;A dumb question: in your code, where should I put the name of my JSON file?</description>
      <pubDate>Fri, 28 Apr 2023 15:17:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872844#M344846</guid>
      <dc:creator>bayzid</dc:creator>
      <dc:date>2023-04-28T15:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872846#M344848</link>
      <description>&lt;P&gt;No idea what code you are talking about.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can either place the name of the JSON file in the LIBNAME statement.&amp;nbsp; Or you can use a FILENAME statement to make a fileref that points to the JSON file and then use the fileref in the LIBNAME statement.&amp;nbsp; If the fileref and the libref that the LIBNAME is defining are the same then you don't need to tell the LIBNAME statement what fileref to use, it will just look for one with that same name.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename myfile 'xxx.json';
libname myfile json ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Apr 2023 15:24:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872846#M344848</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-28T15:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872848#M344850</link>
      <description>I was talking about the following.&lt;BR /&gt;filename json temp;&lt;BR /&gt;proc json out=json;&lt;BR /&gt;export sashelp.class;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;filename map temp;&lt;BR /&gt;libname json json map=map automap=reuse;&lt;BR /&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;infile map;&lt;BR /&gt;input;&lt;BR /&gt;put _infile_;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Fri, 28 Apr 2023 15:28:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872848#M344850</guid>
      <dc:creator>bayzid</dc:creator>
      <dc:date>2023-04-28T15:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872851#M344851</link>
      <description>&lt;P&gt;Replace the TEMP fileref engine with the actual name of the file.&lt;/P&gt;
&lt;P&gt;So if you have a json file name myfile.json and you want to write the map file a file name myfile.map then you would run:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename json 'myfile.json';
filename map 'myfile.map';
libname json json map=map automap=reuse;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you could look at myfile.map and make the desired changes and then try reading the JSON file using code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename json 'myfile.json';
filename map 'myfile.map';
libname json json map=map ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Apr 2023 15:32:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872851#M344851</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-28T15:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872854#M344853</link>
      <description>Thanks. Got it.&lt;BR /&gt;Is there any way to change all the TYPE to Character and length to a fixed number by doing some code? This is because I have thousands of files and need to pass a macro through them.</description>
      <pubDate>Fri, 28 Apr 2023 15:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872854#M344853</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-04-28T15:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872858#M344855</link>
      <description>&lt;P&gt;I posted the steps for doing that in my first answer to this question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But do it manually first to make sure you know what works.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 15:54:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872858#M344855</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-28T15:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872887#M344872</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/437116"&gt;@BayzidurRahman&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks. Got it.&lt;BR /&gt;Is there any way to change all the TYPE to Character and length to a fixed number by doing some code? This is because I have thousands of files and need to pass a macro through them.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;For a worked example post a small example JSON file.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 18:02:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872887#M344872</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-28T18:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872920#M344890</link>
      <description>&lt;P&gt;I have 23 types JSON file with same structure but different variables. Attached 3 types of file.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 20:42:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/872920#M344890</guid>
      <dc:creator>bayzid</dc:creator>
      <dc:date>2023-04-28T20:42:38Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data from JSON as charcater</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/873003#M344933</link>
      <description>&lt;P&gt;So first have SAS make a MAP file for one of the file types.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let filename=c:\downloads\json\AmtProduct_xx.json;
filename rawmap "c:\downloads\json\Amt_Product_rawmap.json";
libname json json "&amp;amp;filename" map=rawmap automap=create;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then have SAS read the map itself as a JSON file.&amp;nbsp; Merge the two tables back together to make it more useful.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname rawmap json ;
data variables;
  merge rawmap.datasets rawmap.datasets_variables;
  by ordinal_datasets;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result so far:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1682796427978.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83409i62E19AF8CFDA4BFB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1682796427978.png" alt="Tom_0-1682796427978.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Now if you want those other three variables to be CHARACTER you need to change the TYPE value from NUMERIC to CHARACTER.&amp;nbsp; &amp;nbsp;And if you want a map file that will also make the variables with SAME length you need to have a LENGTH variable instead of CURRENT_LENGTH variable.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;This is where you will need to make actual decisions.&amp;nbsp; Which variables should be NUMERIC and which should be CHARACTER?&amp;nbsp; For the CHARACTER variables how long each one needs to be.&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So let's do a quick a dirty approach and just set every variable to CHARACTER and set the length to 200 for every one.&amp;nbsp; While we are at at let's rename the ordinal variable to ROW.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data variables;
  set variables;
  if type = 'ORDINAL' then name='ROW';
  else do;
    type='CHARACTER';
    LENGTH=200;
  end;
  drop current_length;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_1-1682796907785.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83410i316B1F3526E2C211/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_1-1682796907785.png" alt="Tom_1-1682796907785.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Now that we have the metadata we want the JSON engine to use when converting the JSON text into SAS dataset(s) we need to write that back out as a MAP file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename map "c:\downloads\json\Amt_Product_map.json";
data _null_;
  file map ;
  if _n_=1 then put '{"DATASETS":' / '[{' @ ;
  if eof then put '}]'/ '}' ;
  set variables end=eof ;
  by ordinal_datasets;
  if first.ordinal_datasets then do;
    if _n_ &amp;gt; 1 then put ',' @;
    put '"DSNAME":' dsname :$quote. ',"TABLEPATH":' tablepath :$quote.
     /  ' ,"VARIABLES":'
     /  '  [' @
    ;
  end;
  else put '  ,' @;
  put '{"NAME":' name :$quote. ',"TYPE":' type :$quote. ',"PATH":' path :$quote. @ ;
  if length then put ',"LENGTH":' length @;
  put '}' ;
  if last.ordinal_datasets then put '  ]' ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is what the new map file looks like:&lt;/P&gt;
&lt;PRE&gt;{"DATASETS":
[{"DSNAME":"root" ,"TABLEPATH":"/root"
 ,"VARIABLES":
  [{"NAME":"ROW" ,"TYPE":"ORDINAL" ,"PATH":"/root" }
  ,{"NAME":"AmtProductId" ,"TYPE":"CHARACTER" ,"PATH":"/root/AmtProductId" ,"LENGTH":200 }
  ,{"NAME":"CTPP_Id" ,"TYPE":"CHARACTER" ,"PATH":"/root/CTPP_Id" ,"LENGTH":200 }
  ,{"NAME":"TPP_Id" ,"TYPE":"CHARACTER" ,"PATH":"/root/TPP_Id" ,"LENGTH":200 }
  ,{"NAME":"MPP_Id" ,"TYPE":"CHARACTER" ,"PATH":"/root/MPP_Id" ,"LENGTH":200 }
  ]
}]
}
&lt;/PRE&gt;
&lt;P&gt;Now let's use it to read the original JSON file and check how the variables are defined and how a few of the observations look.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname json json "&amp;amp;filename" map=map;
proc contents data=json.root varnum;
run;
proc print data=json.root(obs=10);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_2-1682797321042.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83411iE6BF14FEC4217B69/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_2-1682797321042.png" alt="Tom_2-1682797321042.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;So you just need to repeat that process 23 times for the 23 different types of files you have.&amp;nbsp; Make sure to set the lengths long enough for any values that might exist in the other files you have not check yet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Apr 2023 20:31:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-from-JSON-as-charcater/m-p/873003#M344933</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-29T20:31:20Z</dc:date>
    </item>
  </channel>
</rss>

