楼主: taoyuanjl
1863 15

[问答] format不产新变量? [推广有奖]

  • 0关注
  • 0粉丝

硕士生

14%

还不是VIP/贵宾

-

威望
0
论坛币
1267 个
通用积分
2.5000
学术水平
2 点
热心指数
7 点
信用等级
2 点
经验
1117 点
帖子
66
精华
0
在线时间
141 小时
注册时间
2016-2-3
最后登录
2025-9-1

楼主
taoyuanjl 发表于 2020-3-3 16:43:38 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
data  a;
format x;
Informat y $9.;
run;

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

二维码

扫码加我 拉你入群

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

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

关键词:format FORMA form For Mat SAS程序

回帖推荐

Cecilia_Xi 发表于13楼  查看完整内容

为什么az数据集显示的是1E3,我想你的误区在于没有意识到打开的az数据集是在viewtable的状态(请看上一条回复图片高亮的部分)打开数据集后的ViewTable就是按format格式展示。 此外,你可以 试试在数据集az的基础上用以下code: data b; set az; format x 4.; run; 如果没有正确按informat 5. 读入,这里的format4. 怎么还会起作用呢? 或者你可以理解informat是behind the scene,不是直接能看出来 ...

沙发
Cecilia_Xi 在职认证  发表于 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

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

板凳
taoyuanjl 发表于 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.
我不明白为啥是这个结果?

报纸
Cecilia_Xi 在职认证  发表于 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

地板
taoyuanjl 发表于 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;

7
Cecilia_Xi 在职认证  发表于 2020-3-5 18:53:53
taoyuanjl 发表于 2020-3-5 14:31
但format用于设置输出数据的格式,读入数据格式用informat,而informat x 5.0 y $8.0;
打开数据集后的ViewTable就是按format格式展示(Formats tell SAS how to display a variable when printed to the output window or viewed in a Viewtable window.)

8
taoyuanjl 发表于 2020-3-5 21:40:08
Cecilia_Xi 发表于 2020-3-5 18:53
打开数据集后的ViewTable就是按format格式展示(Formats tell SAS how to display a variable when print ...
tableview.png

打开数据集显示x的informat值为5,format值为3

tableview.png (27.91 KB)

tableview.png

9
taoyuanjl 发表于 2020-3-5 21:54:53
Cecilia_Xi 发表于 2020-3-5 18:53
打开数据集后的ViewTable就是按format格式展示(Formats tell SAS how to display a variable when print ...
tableview.png format值为3,informat值为5.

10
taoyuanjl 发表于 2020-3-6 06:28:11
Cecilia_Xi 发表于 2020-3-5 18:53
打开数据集后的ViewTable就是按format格式展示(Formats tell SAS how to display a variable when print ...
我的理解format用于控制数据显示,而informat用于控制数据读入,例如对第一个观测来说,az表中x的值应该是1234,但显示是1E3.
但通过我查看az表,x的值保存的就是1E3,说明读入也是按照format x 3.的格式。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-25 20:23