You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

添加行后SAS Proc SQL出现VALUES子句列数不匹配错误求助

SAS INSERT语句报错原因解析

你遇到的ERROR: VALUES clause 1 attempts to insert more columns than specified after the INSERT table name错误,核心原因出在VALUES子句里的数值写法:

你写的1,799用逗号做了千分位分隔,SAS会把这个逗号当成值的分隔符,将其识别成1和799两个独立的数值。这样一来,VALUES里就有了6个值,而你指定插入的列只有5个,数量不匹配就触发了报错。

再看你的数据集,RetailUnitCost是数值型变量,虽然data步里读取的是带$和逗号的格式,但SAS内部存储的是纯数值,所以插入时不能用带逗号的写法。

修正后的代码

把VALUES里的1,799改成纯数值1799即可:

data productv;
input  Productnum Productnam $ 9-31 ManufacturerNumber  33-36 ProductType $ 43-54 RetailUnitCost 57-63  ;
datalines;
5009    Dream Machine           500       Workstation   $3,200 
4506    Business Machine        450       Workstation   $3,345 
2101    Travel Laptop           400       Laptop        $2,760 
2212    Analog Cell Phone       230       Phone         $35 
4509    Digital Cell Phone      245       Phone         $175 
5003    Office Phone            560       Phone         $145 
1110    Spreadsheet Software    134       Software      $300 
1200    Database Software       113       Software      $799 
3409    Statistical Software    243       Software      $1,899 
2102    Wordprocessor Software  245       Software      $345 
2200    Graphics Software       246       Software      $599 
;

proc sql;
insert into productv (Productnum, Productnam, ManufacturerNumber, ProductType, RetailUnitCost)
VALUES (3480, 'Desktop Computer' , 780 , 'Workstation' , 1799);
select *
from productv;
quit;

补充说明

如果需要显示带千分位的格式,可以后续用format RetailUnitCost dollar8.2;这类语句来设置输出格式,插入数据时必须用SAS能识别的纯数值格式。

内容的提问来源于stack exchange,提问作者Ryan Andrews

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 22:42:48