我有一个文本文件,其中两个不同的列具有相同的名称。如下图所示。
对于SystBP
,我需要将第一个SystBP
更改为SystBP_B
,第二个SystBP
更改为SystBP_E
。
有人可以在这方面为我提供一些帮助吗?
答案 0 :(得分:1)
我会安排观察时间。
data test;
infile cards4 firstobs=2;
input id :$8. week @;
do time = 'STR','END';
input SystBP DiastBP Pulse Stress @;
output;
end;
cards;
ID Week SystBP DiastBP Pulse Stress SystBP DiastBP Pulse Stress
1 1 134 44 66 5.8 134 44 66 5.8
;;;;
run;
答案 1 :(得分:1)
在SAS Base中编程时,有时您不应该期望SAS从文本文件中读取列名并将其解释为变量名。
您必须指示SAS第一个数据行是什么,值的写入位置以及应如何解释它们(文本,数字,日期等)。您可以使用infile
和{ {1}}数据步骤中的语句。
您自己编写代码时,就可以完全控制。
input
当您使用标记将数据作为图像而不是文本插入时,我不得不猜测位置,因此您必须对其进行校正。
答案 2 :(得分:0)
INFILE
选项FIRSTOBS=
将使您INPUT
从第3行开始的数据。
数据文件:C:\temp\bp-survey.txt
Start End
ID Week SystBP DiastBP Pulse Stress SystBP DiastBP Pulse Stress
1 1 134 44 66 5.8 134 44 66 5.8
...
程序
filename survey 'c:\temp\bp-survey.txt';
data want;
infile survey firstobs=3;
input
ID Week
SystBP_start DiastBP_start Pulse_start Stress_start
SystBP_end DiastBP_end Pulse_end Stress_end
;
run;
ods html ;
proc print data=want;
run;