Here is the input JSON file. It have to parse in SAS dataset.
\"results\":
[
{
\"acct_nbr\": 1234,
\"firstName\": \"John\",
\"lastName\": \"Smit
To answer your question with a SAS-only solution, your problems are twofold:
SCAN
instead of substr
to get the un-comma/quotationed portionacct_nbr
is a number, so you need to remove the final quotation mark from the input.Here's the correct code (I changed directories, you'll need to change them back):
filename data 'c:\temp\json.txt';
data testdata2;
infile data lrecl = 32000 truncover scanover;
input
@'"acct_nbr": ' acct_nbr $255.
@'"streetAddress": "' streetAddress $255.
@'"city": "' city $255.
@'"state": "' state $2.
@'"postalCode": "' postalCode $255.;
acct_nbr=scan(acct_nbr,1,',"');
streetAddress = scan(streetAddress,1,',"');
city = scan(city,1,',"');
state = scan(state,1,',"');
postalCode = scan(postalCode,1,',"');
run;
proc print data=testdata2;
RUN;