&符号(“&")在 put 语句中有什么作用? [英] What does an ampersand ("&") do in a put statement?

查看:46
本文介绍了&符号(“&")在 put 语句中有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我熟悉 SAS putinput 语句中的 :~ 修饰符.&input 语句中的行为也有很好的文档记录.但是 &put 语句中做了什么?

I'm familiar with the :, and ~ modifiers in SAS put and input statements. The behaviour of & in an input statement is also fairly well documented. But what does & do in a put statement?

它似乎与 : 有类似的效果,触发修改后的列表输出而不是格式化输出,但我找不到有关此行为的任何文档.

It seems to have a similar effect to :, triggering modified list output rather than formatted output, but I can't find any documentation of this behaviour.

例如

data _null_;
  set sashelp.class;
  file 'c:\temp\output.csv' dlm=',';
  put Name Sex Age & 4. Height Weight;
run; 

推荐答案

引自 SAS 9.4 部分 INPUT Statement, List 下的在线文档

Quoting from the on-line documentation in the section of SAS 9.4 under INPUT Statement, List

&

表示一个字符值可以有一个或多个单个嵌入的空格.此格式修饰符从下一个非空白列读取值,直到指针到达两个连续的空白、变量的定义长度或输入行的末尾,以先到者为准.

indicates that a character value can have one or more single embedded blanks. This format modifier reads the value from the next non-blank column until the pointer reaches two consecutive blanks, the defined length of the variable, or the end of the input line, whichever comes first.

限制:&修饰符必须跟在它影响的变量名和 $ 符号之后.

Restriction: The & modifier must follow the variable name and $ sign that it affects.

提示:如果您在 & 之后指定信息修饰符,格式修饰符的终止条件保留两个空格.

Tip: If you specify an informat after the & modifier, the terminating condition for the format modifier remains two blanks.

这是示例部分的示例:

示例读取包含嵌入空白的字符数据

Example Reading Character Data That Contains Embedded Blanks

此 DATA 步骤中的 INPUT 语句使用 &带有列表输入的格式修饰符以读取包含嵌入空格的字符值.

The INPUT statement in this DATA step uses the & format modifier with list input to read character values that contain embedded blanks.

data list;
   infile file-specification;
   input name $ & score;
run;

它可以读取这些输入数据记录:

It can read these input data records:

----+----1----+----2----+----3----+
Joseph   11 Joergensen  red
Mitchel  13 Mc Allister  blue
Su Ellen  14 Fischer-Simon  green

&修饰符跟在它在 INPUT 语句中影响的变量之后.由于此格式修饰符跟在 NAME 之后,因此必须至少有两个空格将输入数据记录中的 NAME 字段与 SCORE 字段分开.

The & modifier follows the variable that it affects in the INPUT statement. Because this format modifier follows NAME, at least two blanks must separate the NAME field from the SCORE field in the input data records.

您还可以使用格式修饰符指定信息,如下所示:

You can also specify an informat with a format modifier, as shown here:

input name $ & +3 lastname & $15. team $;

此外,此 INPUT 语句读取相同的数据以证明您不需要读取输入记录中的所有值.+3 列指针控件将指针移过分数值以读取 LASTNAME 和 TEAM 的值.

In addition, this INPUT statement reads the same data to demonstrate that you are not required to read all the values in an input record. The +3 column pointer control moves the pointer past the score value in order to read the value for LASTNAME and TEAM.

这篇关于&符号(“&")在 put 语句中有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆