<?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: Infile for one long line of data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Infile-for-one-long-line-of-data/m-p/580901#M165053</link>
    <description>&lt;P&gt;If you are using SAS 9.4 maintenance 4 or better, you can use the &lt;A href="https://go.documentation.sas.com/?docsetId=lestmtsglobal&amp;amp;docsetTarget=n1jfdetszx99ban1rl4zll6tej7j.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;JSON LIBNAME engine&lt;/A&gt; to read in your line of JSON. Here is the code I threw together that produces your results. Note that MAP='MY.MAP' in the LIBNAME statement is just a file name for the JSON LIBNAME engine to place the generated JSON map file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname x json 'sasuser\jsonInfile1.txt' map='my.map' automap=reuse;

data work.xaxis(keep=value rename=(value=xaxis))
     work.yaxis(keep=value rename=(value=yaxis))
     work.col  (keep=value rename=(value=col)) 
     work.row  (keep=value rename=(value=row)) 
     work.val  (keep=value rename=(value=val));
   set x.alldata;
   if (V = 1)
     then do;
	   if (p2 EQ "")
	      then do;
		select (p1);
		  when ("yaxis") output work.yaxis;
		  when ("xaxis") output work.xaxis;
                  otherwise put "Unexpected :" p1;
		  end;
	    end;
	  else do;
 	    select (substr(p2,1,3));
	      when ("col") output work.col;
	      when ("val") output work.val;
	      when ("row") output work.row;
	      otherwise put "Unexpected :" p2;
	      end;
	  end;
       end;
   run;

data work.merged;
   merge work.xaxis work.yaxis work.col work.row work.val;
   run;

proc print data=work.merged; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jsonInfile.PNG" style="width: 424px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/31706i27040A97008AABED/image-size/large?v=v2&amp;amp;px=999" role="button" title="jsonInfile.PNG" alt="jsonInfile.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Aug 2019 17:21:40 GMT</pubDate>
    <dc:creator>BillM_SAS</dc:creator>
    <dc:date>2019-08-13T17:21:40Z</dc:date>
    <item>
      <title>Infile for one long line of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infile-for-one-long-line-of-data/m-p/580647#M164958</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am beginning my second SAS program and have hit a bit of a roadblock. My raw data are in a .txt all on one line, and are grouped together by 5 separate categories: yaxis, xaxis, col, val, and row (example posted below). The .txt has the curly and regular brackets, as well as quotes, commas, and semi-colons as shown below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;{"yaxis": 128, "xaxis": 120, "col": [111, 108, 109, 110, 108, 101], "val": [114.35938, 89.78516, 67.86719, 36.28906, 62.14258, 55.28305], "row": [43, 52, 52, 52, 53, 54]}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The yaxis and xaxis fields always have 1 value, but the col, val, and row fields can have anywhere from 0 to hundreds of values (here there are 6 separate values). The col, val, and row fields are related and should always contain the same quantity of values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I would want is something like (yaxis and xaxis could be filled in with 128 and 120 for each cell):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Read in Data.PNG" style="width: 321px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/31681iB7E017B9029DB424/image-size/large?v=v2&amp;amp;px=999" role="button" title="Read in Data.PNG" alt="Read in Data.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried using dlmstr = ', "'; and delimstr = ': '; to little success. Any guidance would be appreciated. Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2019 19:59:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infile-for-one-long-line-of-data/m-p/580647#M164958</guid>
      <dc:creator>how2infile</dc:creator>
      <dc:date>2019-08-12T19:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: Infile for one long line of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infile-for-one-long-line-of-data/m-p/580661#M164961</link>
      <description>That looks like XML or JSON. If so, you can try either the XML or JSON libnames to read in the data instead of INFILE.</description>
      <pubDate>Mon, 12 Aug 2019 20:54:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infile-for-one-long-line-of-data/m-p/580661#M164961</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-08-12T20:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: Infile for one long line of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infile-for-one-long-line-of-data/m-p/580767#M164998</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dlm='{},[] :';
input x : $40. @@;
x=dequote(x);
cards;
{"yaxis": 128, "xaxis": 120, "col": [111, 108, 109, 110, 108, 101], "val": [114.35938, 89.78516, 67.86719, 36.28906, 62.14258, 55.28305], "row": [43, 52, 52, 52, 53, 54]}
;
run;
data temp; 
 set have;
 if anyalpha(x) then group+1;
run;
proc transpose data=temp out=temp1(drop=_name_ group rename=(col1=id));
by group;
var x;
run;
proc transpose data=temp1 out=want;
var col:;
id id;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Aug 2019 12:05:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infile-for-one-long-line-of-data/m-p/580767#M164998</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-08-13T12:05:55Z</dc:date>
    </item>
    <item>
      <title>Re: Infile for one long line of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infile-for-one-long-line-of-data/m-p/580901#M165053</link>
      <description>&lt;P&gt;If you are using SAS 9.4 maintenance 4 or better, you can use the &lt;A href="https://go.documentation.sas.com/?docsetId=lestmtsglobal&amp;amp;docsetTarget=n1jfdetszx99ban1rl4zll6tej7j.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;JSON LIBNAME engine&lt;/A&gt; to read in your line of JSON. Here is the code I threw together that produces your results. Note that MAP='MY.MAP' in the LIBNAME statement is just a file name for the JSON LIBNAME engine to place the generated JSON map file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname x json 'sasuser\jsonInfile1.txt' map='my.map' automap=reuse;

data work.xaxis(keep=value rename=(value=xaxis))
     work.yaxis(keep=value rename=(value=yaxis))
     work.col  (keep=value rename=(value=col)) 
     work.row  (keep=value rename=(value=row)) 
     work.val  (keep=value rename=(value=val));
   set x.alldata;
   if (V = 1)
     then do;
	   if (p2 EQ "")
	      then do;
		select (p1);
		  when ("yaxis") output work.yaxis;
		  when ("xaxis") output work.xaxis;
                  otherwise put "Unexpected :" p1;
		  end;
	    end;
	  else do;
 	    select (substr(p2,1,3));
	      when ("col") output work.col;
	      when ("val") output work.val;
	      when ("row") output work.row;
	      otherwise put "Unexpected :" p2;
	      end;
	  end;
       end;
   run;

data work.merged;
   merge work.xaxis work.yaxis work.col work.row work.val;
   run;

proc print data=work.merged; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jsonInfile.PNG" style="width: 424px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/31706i27040A97008AABED/image-size/large?v=v2&amp;amp;px=999" role="button" title="jsonInfile.PNG" alt="jsonInfile.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2019 17:21:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infile-for-one-long-line-of-data/m-p/580901#M165053</guid>
      <dc:creator>BillM_SAS</dc:creator>
      <dc:date>2019-08-13T17:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: Infile for one long line of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infile-for-one-long-line-of-data/m-p/581159#M165142</link>
      <description>&lt;P&gt;Thanks for the help all!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Learned a lot of new syntax along the way &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 14:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infile-for-one-long-line-of-data/m-p/581159#M165142</guid>
      <dc:creator>how2infile</dc:creator>
      <dc:date>2019-08-14T14:48:39Z</dc:date>
    </item>
  </channel>
</rss>

