SAS中关联表字段类型不同时的解决办法
来源:互联网 发布:武汉网络电视 编辑:程序博客网 时间:2024/06/06 19:51
项目里出了个奇葩问题,小组里建表人员把两个表要关联的字段建成了不同的类型,一个整成了数字型,一个又整成了字符串型.两个表结果如下:
create table mdlst_batch(
model_id varchar2(20) ,
batch_no varchar2(10)
);
create table mdl_inf(
id number(20),
model_code varchar2(40)
);
要关联的两个字段是mdlst_batch.model_id与mdl_inf.id
两表数据如下:
id model_code
12345678 AEIDASD_AFIELSD_AE
12345679 AEIDASD_AFIELSD_AE01
12345690 AEIDASD_AFIELSD_AE02
model_id batch_no
12345678 B12341234
如果直接关联model_id与id:
proc sql;
select a.model_id,a.batch_no,b.model_code
from mdlst_batch a,mdl_inf b
where a.model_id = b.id;
quit;
执行代码会报如下错误 :
正确处理方法:在data步中衍生一个变量,再关联
data mdl_inf;
set mdl_inf;
model_id=input(id,$20.);
run;
proc sql;
select a.model_id, a.batch_no, b.model_code
from mdlst_batch a,
mdl_inf b
where a.model_id=b.model_id;
quit;
运行结果如下:
补充:
还可以采用以下方法
方法一:
proc sql;
select a.model_id, a.batch_no, b.model_code
mdl_inf b
where input(a.model_id,20.)=b.id;
quit;
需要注意的是input函数中的第一个参数要是字符型的才行
方法二:
proc sql;
select a.model_id, a.batch_no, b.model_code
mdl_inf b
where a.model_id=put(b.id,20.);
quit;注意put函数的参数b.id是数字型
并且put中的格式不能用$9.而应该用put(b.id,9.);
用$9.会报错:
参考:SAS帮助;
Use the PUT function to convert a numeric value to a character value.The PUT function has no effect on which
formats are used in PUT statements or which formats are assigned to variables in data sets.
You cannot use the PUT function to directly change the type of variable in a data set from numeric to character.However, you can create a new character variable as the result of the PUT function.Then,if needed,use the DROP statement to drop the original numeric variable,followed by the RENAME statement to rename the new variable back to the original variable name.
The INPUT function enables you to convert the value of source by using a specified informat.The informat
determines whether the result is numeric or character.Use INPUT to convert character values to numeric values or other character values.
- SAS中关联表字段类型不同时的解决办法
- 查找表字段的类型
- MyBatis关联查询,表字段相同,resultMap映射问题的解决办法
- MyBatis关联查询,表字段相同,resultMap映射问题的解决办法
- MyBatis关联查询,表字段相同,resultMap映射问题的解决办法
- 数据库表字段中类型变更
- 使用PreparedStatementSetter 设置参数跟 表字段类型不匹配出现的错误
- 关于Yii中CGridView关联表字段的filter问题解决方法
- 查询表字段类型
- MySQL表字段类型
- yii 关联表字段排序
- Yii关联表字段查询
- VO的Query关联其他表字段用于判断
- thinkphp5.0.2 多对多模型中插入中间表字段不存在的解决办法
- Hibernate映射文件中对应的mysql数据库表字段的类型
- C#中去的Oracle中的表字段类型,长度,精度
- SqlServer2008中便捷查看表字段备注类型默认值的方法
- mysql更改表字段类型
- zip文件
- OGNL
- java 同步锁(synchronized)
- Java - 字符流缓冲区 - BufferedReader - BufferedWriter
- nyoj 73 比大小 【java大数】
- SAS中关联表字段类型不同时的解决办法
- Codeforces 86D Powerful array 分块
- 关于解题的思路与方法
- JSP中404错误的解决
- 21中介模式
- Downloading Android Source
- [2747]循环节(next数组) SDUT
- [教程]逆向反汇编第十一课
- 22装饰模式