我想将文本从下面的表单(JSON)更改为sas数据集。
[
{
"id":86374,
"course":[
"artificial intelligence",
"data structure",
"linear algebra"
]
}
{
"id":12319,
"course":[
"data structure",
"algorithm",
"database",
"linear algebra"
]
}
...
]
由于课程的数量因ID而异,我不知道如何将所有课程名称(可能以数组形式)保存到sas数据集中。
对于Json文件,可以通过proc groovy导入,这是数据步骤。如果不知道每个学生参加了多少门课程,则使用临时数组,然后将每个ID的数据转置为宽数据。
filename myjson 'd:\json.txt';
data temp;
array temp (100) $100. _temporary_;
infile myjson lrecl=10000 truncover scanover ;
input @'"id":' ID $10.;
input;
do i=1 by 1 ;
input temp(i) $100. ;
if not anyalpha(temp(i)) then leave;
end;
id=compress(id,',');
do j=1 by 1;
var=compress(temp(j),',""');
if not anyalpha(temp(j)) then leave;
output;
end;
drop i j;
run;
proc transpose data=temp out=want(drop=_name_) prefix=Couse;
by id notsorted;
var var;
run;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句