我需要將某些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