我正在尝试从JSON文件读取数据并将值存储在SAS数据集中这是我的JSON文件test.json
[
{
"id":1,
"name":"Johnson, Smith and Jones Co.",
"amount":345.33,
"Remark":"Pays on time"
},
{
"id":2,
"name":"Sam, Smith",
"amount":993.44,
"Remark":""
},
{
"id":3,
"name":"Barney & Company",
"amount":0,
"Remark":"Great to work with and always pays with cash."
},
{
"id":4,
"name":"Johnson's Automotive",
"amount":2344,
"Remark":""
}
]
现在,我希望输出像简单的SAS数据集一样,可以以表格形式获取。如果我使用proc打印数据集,它将看起来像:
id name amount Remark
1 Johnson, Smith and Jones Co. 345.33 Pays on time
2 Sam, Smith 993.44
3 Barney & Company 0 Great to work with and always pays with cash.
4 Johnson's Automotive 2344
这是我的方法,但没有得到正确的输出。
LIBNAME src '/home/user/read_JSON';
filename data '/home/user/read_JSON/test.json';
data src.testdata;
infile data lrecl = 32000 truncover scanover;
input @'"id": "' id $255. @'"name": "' name $255. @'"amount": "' amount @'"Remark": "' Remark $255.;
id = substr(id,1,index(id,'",')-2);
name = substr( name,1,index( name,'",')-2);
amount = substr(amount,1,index(amount,'",')-2);
Remark = substr(Remark,1,index(Remark,'",')-2);
run;
proc print data=src.testdata;
RUN;
任何想法我怎么做???
将firstobs = 3设置为忽略前两行,然后使用/
输入修饰符读取下一行。两条尾随/
忽略后续的JSON分隔符。
数据测试数据; infile数据lrecl = 32000 truncover dsd firstobs = 3; 输入@'“ id”:'id $ 255。 / @'“ name”:'名称$ 255。 / @'“金额”:'金额 / @'“备注”:'备注$ 255。 / / ; 跑;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句