DATA Step, Macro, Functions and more

reading in json data

Reply
Occasional Contributor
Posts: 15

reading in json data

here is the error when I read this data. there are no observations. Why ?

 

 filename data '\\kashmir\BFD\sample_json1_may26.txt';


6300  data datatest;
6301   infile data lrecl = 32000 truncover scanover;
6302   input @'"text": "' text $255. @'"from_user": "' from_user $255. @'"created_at": "' created_at
6302! $255. ;
6303  /*text = substr(text,1,index(text,'",')-2); from_user = substr( from_user,1,index(
6303! from_user,'",')-2);
6304  created_at = substr(created_at,1,index(created_at,'",')-2); run;
6305    */

NOTE: The infile DATA is:
      Filename=\\kashmir\BFD\sample_json1_may26.txt,
      RECFM=V,LRECL=32000,File Size (bytes)=1989,
      Last Modified=26May2017:12:28:24,
      Create Time=26May2017:12:09:11

NOTE: 3 records were read from the infile DATA.
      The minimum record length was 1.
      The maximum record length was 1134.
NOTE: SAS went to a new line when INPUT @'CHARACTER_STRING' scanned past the end of a line.
NOTE: The data set WORK.DATATEST has 0 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.03 seconds


6306  proc print data=dataset;run;
ERROR: File WORK.DATASET.DATA does not exist.

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

 

Super User
Posts: 10,497

Re: reading in json data

Without actually seeing the data file here is something to check:

 

When using the Input @'text value' then the value you supply in the code must be exactly as it appears in the source file.

If the file has "Text value" then it does not match 'text value'

 

Also the "Minimum record length was 1" may indicate you don't even want to attempt the read the first line. Perhaps add "firstobs=2" to accomplish that.

Regular Contributor
Posts: 182

Re: reading in json data

If you're using SAS 9.4 you might find the JSON library engine much easier to use than trying to parse it yourself. The details are here

Ask a Question
Discussion stats
  • 2 replies
  • 130 views
  • 0 likes
  • 3 in conversation