【发布时间】:2014-10-02 10:07:56
【问题描述】:
我有一个奇怪的数据集需要导入 SAS,根据格式将记录分成两个表,并完全删除一些记录。数据结构如下:
c Comment line 1
c Comment line 2
t lines init
a 'mme006' M 8 99 15 '111 ME - RANDOLPH ST'
path=no
dwt=0.01 42427 ttf=1 us1=3 us2=0
dwt=#0 42350 ttf=1 us1=1.8 us2=0 lay=3
dwt=>0 42352 ttf=1 us1=0.5 us2=18.13
42349 lay=3
a 'mme007' M 8 99 15 '111 ME - RANDOLPH ST'
path=no
dwt=+0 42367 ttf=1 us1=0.6 us2=0
dwt=0.01 42368 ttf=1 us1=0.6 us2=35.63 lay=3
dwt=#0 42369 ttf=1 us1=0.3 us2=0
42381 lay=3
只需要保留以a、dwt 或整数开头的行。
对于以a 开头的行,所需的输出是这样的表,称为“行”,其中包含行中的前两个非a 值:
name | type
--------+------
mme006 | M
mme007 | M
对于dwt/integer 行,表“itins”如下所示:
anode | dwt | ttf | us1 | us2 | lay
------+------+-----+-----+-------+-----
42427 | 0.01 | 1 | 3.0 | 0.00 |
42350 | #0 | 1 | 1.8 | 0.00 | 3
42352 | >0 | 1 | 0.5 | 18.13 |
42349 | | | | | 3 <-- line starting with integer
42367 | +0 | 1 | 0.6 | 0.00 |
42368 | 0.01 | 1 | 0.6 | 35.63 | 3
42369 | #0 | 1 | 0.3 | 0.00 |
42381 | | | | | 3 <-- line starting with integer
到目前为止我的代码已经差不多了,但还不完全:
data lines itins;
infile in1 missover;
input @1 first $1. @;
if first in ('c','t') then delete;
else if first='a' then do;
input name $ type $;
output lines; end;
else do;
input @1 path=$ dwt=$ anode ttf= us1= us2= us3= lay=;
if path='no' then delete;
output itins; end;
问题:
- “行”表是正确的,但我无法去掉“名称”值周围的引号(例如
'mme006') - 在“itins”表中,“ttf”、“us1”和“us2”已正确填充。但是,“anode”和“lay”始终为空,而“dwt”的值类似于
#0 4236和0.01 42,长度始终为 8 个字符,借用了 应该在“anode”中的部分内容.
我做错了什么?
【问题讨论】:
-
我认为您在这里混合输入法时遇到了麻烦。去掉引号很容易(
dequote()),但另一部分我不知道你可以用这种方式解决,因为anode不能用命名输入读取。 -
感谢
dequote()提示!对于允许在不修改输入数据的情况下导入anode的替代方法有什么建议吗?