我需要将某些JSON转换为机器友好格式(例如CSV,Excel,Stata,SAS),并且我正在使用SAS,因为我的文件很大。SAS导入JSON
的观察一个例子:
{"business_id": "vcNAWiLM4dR7D2nwwJ7nCA", "full_address": "4840 E Indian School Rd\nSte 101\nPhoenix, AZ 85018", "hours": {"Tuesday": {"close": "17:00", "open": "08:00"}, "Friday": {"close": "17:00", "open": "08:00"}, "Monday": {"close": "17:00", "open": "08:00"}, "Wednesday": {"close": "17:00", "open": "08:00"}, "Thursday": {"close": "17:00", "open": "08:00"}}, "open": true, "categories": ["Doctors", "Health & Medical"], "city": "Phoenix", "review_count": 9, "name": "Eric Goldberg, MD", "neighborhoods": [], "longitude": -111.98375799999999, "state": "AZ", "stars": 3.5, "latitude": 33.499313000000001, "attributes": {"By Appointment Only": true}, "type": "business"}
我一直在使用由
http://support.sas.com/resources/papers/proceedings13/296-2013.pdf推荐的方式
。
问题是,并非所有的观察结果都有相同的条目。例如,一些观察可能缺少“full_address”。
因此我的示例代码现在
filename data '(filename)';
data datatest; * defines dataset;
infile data lrecl = 32000 truncover scanover;
input
@'"business_id": "' business_id $255.
;
business_id = substr(business_id,1,index(business_id,'",')-1);
IF INDEX(_INFILE_,'"full_address":') > 0
THEN DO;
input @'"full_address": "' full_address $255.;
full_address = substr(full_address,1,index(full_address,'",')-1);
END;
run;
proc print data = work.datatest;
run;
的问题是代码似乎跳过所有其他观察。我怎样才能防止这种情况发生?
我不会将其作为重复关闭,因为这显示了一个有趣的不同问题,但这与[此问题]非常相似(http://stackoverflow.com/questions/21115091/parse-json-object-in -SAS-宏)。 – Joe