Proc 导入过程后我无法更改字符列的长度
I can't change the length of a character column after Proc Import process
第一个 proc import
进程从 Excel 文件中读取 "character" 列。来自 Excel 的数据只有 2 个字符,因此 SAS 创建的列长度为 2.
proc import datafile = "excelfie" out=MainTable DBMS = excel REPLACE;
SHEET = "Sheet1"; GETNAMES=NO; MIXED=YES; USEDATE=YES; SCANTIME=YES; RANGE="A1:C26";
run;
然后我使用 proc append
将另一个 SAS-table(具有相同的列名)插入到主 SAS-table 中,但出现错误,因为 SAS 创建了main table 中的列为 2 个字符长度,新字符数据为 5 位数字。
Proc Append Base=MainTable Data=Table1; Run;
我试图在 proc attend
过程之前将列的长度更改为
data MainTable;
set MainTable;
format Column2 .;
informat Column2 .;
length Column2 ;
run;
Proc Append Base=MainTable Data=Table1; Run;
但我仍然得到同样的错误,因为列格式现在是 $5.,但长度仍然是 2.
我在 Proc append
过程中使用了 Force
选项,它强制对不同格式的数据进行合并过程。
Proc Append Base=MainTable Data=Table1 FORCE NOWARN; Run;
现在我没有得到错误,但它把新数据从 5 位数字截断为 2 位数字。
那我该怎么办?
在您的代码中,"new" MainTable 获取 "old" 的变量,然后读取 LENGTH 语句并忽略它,因为变量 Column2 已从 "old" MainTable 定义.您必须在 SET 语句之前定义新的长度。
data MainTable;
format Column2 .;
informat Column2 .;
length Column2 ;
set MainTable;
run;
第一个 proc import
进程从 Excel 文件中读取 "character" 列。来自 Excel 的数据只有 2 个字符,因此 SAS 创建的列长度为 2.
proc import datafile = "excelfie" out=MainTable DBMS = excel REPLACE;
SHEET = "Sheet1"; GETNAMES=NO; MIXED=YES; USEDATE=YES; SCANTIME=YES; RANGE="A1:C26";
run;
然后我使用 proc append
将另一个 SAS-table(具有相同的列名)插入到主 SAS-table 中,但出现错误,因为 SAS 创建了main table 中的列为 2 个字符长度,新字符数据为 5 位数字。
Proc Append Base=MainTable Data=Table1; Run;
我试图在 proc attend
过程之前将列的长度更改为
data MainTable;
set MainTable;
format Column2 .;
informat Column2 .;
length Column2 ;
run;
Proc Append Base=MainTable Data=Table1; Run;
但我仍然得到同样的错误,因为列格式现在是 $5.,但长度仍然是 2.
我在 Proc append
过程中使用了 Force
选项,它强制对不同格式的数据进行合并过程。
Proc Append Base=MainTable Data=Table1 FORCE NOWARN; Run;
现在我没有得到错误,但它把新数据从 5 位数字截断为 2 位数字。 那我该怎么办?
在您的代码中,"new" MainTable 获取 "old" 的变量,然后读取 LENGTH 语句并忽略它,因为变量 Column2 已从 "old" MainTable 定义.您必须在 SET 语句之前定义新的长度。
data MainTable;
format Column2 .;
informat Column2 .;
length Column2 ;
set MainTable;
run;