gpt4 book ai didi

json - Proc json 在应用格式后产生额外的空白

转载 作者:行者123 更新时间:2023-12-05 03:33:55 24 4
gpt4 key购买 nike

我想将 sas 数据集导出到 json。我需要应用 commax10.1 格式以使其适用于某些语言版本。问题是 fmtnumeric 选项正确地应用了格式,但在引号内插入了额外的空格。我尝试过 trimblanks 和其他选项,但无法摆脱它们。如何删除引号内的空白?注意:我希望值保留在引号内

另外,是否可以用“”替换空值?

示例数据:

data testdata_;
input var1 var2 var3;
format _all_ commax10.1;
datalines;
3.1582 0.3 1.8
21 . .
1.2 4.5 6.4
;
proc json out = 'G:\test.json' pretty fmtnumeric nosastags trimblanks keys;
export testdata_;
run;

在链接中,您可以看到输出的样子。

output of json

最佳答案

使用去除前导和尾随空格的自定义格式函数。

例子:

proc fcmp outlib=work.custom.formatfunctions;
function stripcommax(number) $;
return (strip(put(number,commax10.1)));
endsub;
run;

options cmplib=(work.custom);

proc format;
value commaxstrip other=[stripcommax()];
run;

data testdata_;
input var1 var2 var3;
datalines;
3.1582 0.3 1.8
21 . .
1.2 4.5 6.4
;
proc json out = 'test.json'
pretty
fmtnumeric
nosastags
keys
/*
/* trimblanks */
;
format var: commaxstrip.;
export testdata_;
run;

data _null_;
infile 'test.json';
input;
put _infile_ ;
run;

enter image description here

关于json - Proc json 在应用格式后产生额外的空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70259412/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com