全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1763 15
2020-03-03
data  a;
format x;
Informat y $9.;
run;

请问上面的数据部,为啥x不能产生新变量,而informat可以?
谢谢!

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2020-3-4 23:21:50
因为 format x 后面没有加上具体的format类型:
改这样就可以:

data  a;
format x $9.;
Informat y $9.;
run;

PS. If the variable does not already exist and you create it for the first time in a FORMAT or INFORMAT statement, then SAS defines the variable and its attributes based on the format’s or informat’s category

https://documentation.sas.com/?docsetId=lrcon&docsetTarget=n0bbin3txgxlown1v2v5d8qbc9vq.htm&docsetVersion=9.4&locale=en#p0rk29057on02hn132n5gvkk4870
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2020-3-4 23:25:20
Cecilia_Xi 发表于 2020-3-4 23:21
因为 format x 后面没有加上具体的format类型:
改这样就可以:
不知为何显示有问题,在format x后加 $9. 试试就明白了
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2020-3-5 06:25:07
Cecilia_Xi 发表于 2020-3-4 23:25
不知为何显示有问题,在format x后加 $9. 试试就明白了
我试过,读入数据也是按format的宽度读入,我也有同样的疑问,即使我用如下代码也不行。
data az;
informat x 5.0 y $8.0;
format x 3.0;

input x y;
put x y;
;
cards;
1234  56789
8900  tyui
;
run;

数据集az中保存的x的值为1E3和9E3.
我不明白为啥是这个结果?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2020-3-5 12:18:33
taoyuanjl 发表于 2020-3-5 06:25
我试过,读入数据也是按format的宽度读入,我也有同样的疑问,即使我用如下代码也不行。
data az;
info ...
因为format x 3.0 会把x的format调成宽度为3的格式。换成format x w.d, 其中w大于等于输入数字的实际长度就可以了(如4.0) 2020-03-05_121744.png
附件列表
2020-03-05_121718.png

原图尺寸 9.72 KB

2020-03-05_121718.png

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2020-3-5 14:31:08
Cecilia_Xi 发表于 2020-3-5 12:18
因为format x 3.0 会把x的format调成宽度为3的格式。换成format x w.d, 其中w大于等于输入数字的实际长度 ...
但format用于设置输出数据的格式,读入数据格式用informat,而informat x 5.0 y $8.0;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群