SAS 冒号格式修饰符

SAS colon format modifier

灰色框中的数字代表什么?理解冒号修饰符如何影响 sas 读取值的方式的简单方法是什么?

答案取决于未提供的信息。答案 B 是最佳选择,因为在 INPUT 语句中使用 informats 时应使用冒号修饰符,以防止使用格式化输入模式而不是列表输入模式。否则格式化输入可能会读取过多或过少的字符,并且还可能将光标留在错误的位置以读取下一个字段。

但是,如果您尝试从在线卡中读取该数据,那么这两行就可以正常工作。这是因为内联数据行被填充到下一个 80 字节的倍数。

如果您将这些行放入文件中且行中没有任何尾随空格,则第二行将失败,因为最后一个字段没有 10 个字符可供读取。但是,如果您将 TRUNCOVER 选项(或 PAD)添加到 INFILE 语句中,那么它将起作用。

自己试试吧。 TEST1 和 TEST3 工作。 TEST2 收到一张丢失卡片的便条。

data test1;
  input name $ hired date9. age state $ salary comma10.;
  format hired date9.;
cards;
Donny 5MAR2008 25 FL ,123.50
Margaret 20FEB2008 43 NC 65,150
;

options parmcards=test;
filename test temp ;
parmcards;
Donny 5MAR2008 25 FL ,123.50
Margaret 20FEB2008 43 NC 65,150
;

data test2;
  infile test;
  input name $ hired date9. age state $ salary comma10.;
  format hired date9.;
run;

data test3;
  infile test truncover;
  input name $ hired date9. age state $ salary comma10.;
  format hired date9.;
run;

对于不同的数据,第一个格式化输入也会造成麻烦。例如,如果日期值仅使用 2 位数字作为年份,它就会把事情搞砸。因此它尝试将 FL 读取为年龄,然后将薪水的前 8 个字符读取为 STATE,将空白作为 SALARY。

data test1;
  input name $ hired date9. age state $ salary comma10.;
  format hired date9.;
cards;
Donny 5MAR08 25 FL ,123.50
Margaret 20FEB2008 43 NC 65,150
;

结果:

Obs    name            hired    age    state       salary

 1     Donny       05MAR2008      .    ,123.         .
 2     Margaret    20FEB2008     43    NC           65150