首页 > 解决方案 > 如何在 SAS EG 中手动输入数据

问题描述

刚开始学习 SAS,正在阅读一本使用以下代码创建表的教科书。

Data travel;
    input City $ 1-9 Nights 11 LandCost 13-16 NumberOfEvents 18
          EventDescription $ 20-36 TourGuide $ 38-45
          BackUpGuide $ 47-54;
datalines;
Rome        3 750   7 4 M, 3 G                  D’Amico Torres
Paris       8 1680  6 5 M, 1 other              Lucas Lucas
London      6 1230  5 3 M, 2 G                  Wilson Lucas
New York    6 .     8 5 M, 1 G, 2 other         Lucas D’Amico
Madrid      3 370   5 3 M, 2 other              Torres D’Amico
Amsterdam   4 580   6 3 M, 3 G                  Vandever
;
Run;

这本书给出了预期的输出:

但是,当我运行程序时,它给了我以下信息
在此处输入图像描述

如何解决这个问题? 在此处输入图像描述

标签: sasenterprise-guide

解决方案


你是如何自己输入数据线的?

如果您使用将制表位设置为 4 的编辑器键入它们,并且在键入数据行期间使用了一些制表符,则这些停止可能导致数据与示例代码不对齐。

如果您复制粘贴,则可能源具有选项卡并且编辑器将选项卡扩展到到达制表位的空格。

无论如何,添加“标尺”注释行可以帮助您了解需要对代码或数据行进行哪些调整。

Data travel;
    input City $ 1-9 Nights 11 LandCost 13-16 NumberOfEvents 18
          EventDescription $ 20-36 TourGuide $ 38-45
          BackUpGuide $ 47-54;
datalines;
Rome        3 750   7 4 M, 3 G                  D’Amico Torres
Paris       8 1680  6 5 M, 1 other              Lucas Lucas
London      6 1230  5 3 M, 2 G                  Wilson Lucas
New York    6 .     8 5 M, 1 G, 2 other         Lucas D’Amico
Madrid      3 370   5 3 M, 2 other              Torres D’Amico
Amsterdam   4 580   6 3 M, 3 G                  Vandever
;
*234567890123456789012345678901234567890123456789012345678901234567890123
*        1         2         3         4         5         6         7
*   T   T   T   T   T   T   T   T   T   T   T   T   T   T   T   T   T   T  cursor position after tab hit
;

<NOSTALGIA>

有时我会怀念程序编辑器和COLS等行命令

在此处输入图像描述

SAS 文档似乎正在摆脱程序编辑器文档,就像一个尴尬的成年人可能会对他们十几岁时的糟糕发型图片所做的那样。

祝您The COLS line command displays a special line that indicates the column numbers across the Program Editor window.在documentation.sas.com 上找到好运,但我找不到。

</NOSTALGIA>


推荐阅读