sas中,在不sas 改变变量类型名的情况下,将数值型变为字符型,或者讲字符变为数值

【图文】sas期末复习_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
sas期末复习
&&统计分析
登录百度文库,专享文档复制特权,财富值每天免费拿!
你可能喜欢苹果/安卓/wp
积分 327, 距离下一级还需 123 积分
权限: 自定义头衔, 签名中使用图片
道具: 彩虹炫, 涂鸦板, 雷达卡, 热点灯, 金钱卡, 显身卡, 匿名卡下一级可获得
道具: 抢沙发
购买后可立即获得
权限: 隐身
道具: 金钱卡, 彩虹炫, 雷达卡, 热点灯, 涂鸦板
我有一些数据,其中有一个变量应该是日期,但是是字符型的,我想将其转化为数值型。比如变量trd 有 ,如何将其转化成数值型的90102,谢谢各位大侠!
1# wdxmahone
这种数值型的东西,不能加不能减的,何用?
本帖被以下文库推荐
& |主题: 2385, 订阅: 28
本帖最后由 jingju11 于
11:21 编辑
data _null_;
x = ''; *
y =input(x, yymmdd11.); *
z = put(y, yymmddn.); *
put x= y= z=;
复制代码
......数值型的90102......这种数值型的东西,不能加不能减的,何用?
总评分:&经验 + 3&
论坛币 + 3&
非常棒,谢谢哈
ok thx ar, 好多謝。
SAS有些是由默认的将字符型变量转化为数值型变量的功能啊,也可以用INPUT函数由字符型转换为数值型。
怎么样才能进行日期相减呢~~??求助。。
怎么样才能进行日期相减呢~~??求助。。。 谢谢~~
C100 如果计算日期之间的时间间隔,推荐用SAS提供的一个非常好用的函数:INTCK
不错不错啊!
很有用~~学习了
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
如有投资本站或合作意向,请联系(010-);
邮箱:service@pinggu.org
投诉或不良信息处理:(010-)
论坛法律顾问:王进律师苹果/安卓/wp
积分 1389, 距离下一级还需 836 积分
权限: 自定义头衔, 签名中使用图片, 隐身, 设置帖子权限
道具: 彩虹炫, 涂鸦板, 雷达卡, 热点灯, 金钱卡, 显身卡, 匿名卡, 抢沙发, 提升卡下一级可获得
权限: 设置回复可见道具: 沉默卡
购买后可立即获得
权限: 隐身
道具: 金钱卡, 彩虹炫, 雷达卡, 热点灯, 涂鸦板
悲催签到天数: 128 天连续签到: 1 天[LV.7]常住居民III
本帖最后由 guanglei 于
22:30 编辑
%do j = 1 %to 15;
& &proc model noprint data =&&&&exogenous r f VA
& && && & e = a*probnorm((log(a/f) + (r+va*va/2))/VA) -
& && && & f*exp(-r)*probnorm((log(a/f) + (r-va*va/2))/VA);&&solve a/out=
& && && &num = _n_;& &
& && && &num = _n_;& &&&
& && && &&&l1p = lag1(permno);& &l1a = lag1(a);
& && & if l1p = permno then ra = log(a/l1a);
& &proc means noprint data =& && && &output out =
& && & if _stat_ = 'MEAN';&&mu = 252*& &
& && & if _stat_ = 'STD'; va1 = sqrt(252)*RA;
& && && && && &if va1 & 0.01 then va1 = 0.01; keep permno va1;
& && & vdif = va1 -
& && && && && &if abs(vdif) & 0.001 and vdif ne . then conv = 1;
& && & if conv = 1;& &assetvol = va1; by pe&&
& && & if permno ne lag1(permno);& &curdat = 100*&yyy + &&&iter = &j;
& && && &&&drop va ra l1p l1
& && & if conv ne 1;& &va = va1;& &drop va1;
%复制代码变量permno是股票的代码。运行到“& & if permno ne lag1(permno);& &curdat = 100*&yyy + &&&iter = &j;” 时会提示:ERROR: 变量 permno 已定义为字符型和数值型。这是什么原因呢?恳请高人解答啊!
原因: 两个数据集参加运算时,相同变量有不同的类形。
/* run the following code and look at the results */
/* to see if there is any difference in the last column */
select memname, name, type
from dictionary.columns
where libname='WORK' and name='permno';
三人行,必有我师焉;择其善者而从之,其不善者而改之
本帖最后由 yongyitian 于
13:19 编辑
原因: 两个数据集参加运算时,相同变量有不同的类形。
/* run the following code and look at the results */
/* to see if there is any difference in the last column */
& &select memname, name, type
& &from dictionary.columns
& &where libname='WORK' and name='permno';
检查你数据集two bob bar中的permno是不是即有数值型又有字符型
欢迎加入亚太地区第一R&Python数据挖掘群: ;
这个错误应该不是“& & if permno ne lag1(permno);& &curdat = 100*&yyy + &&&iter = &j;” 这一步产生的。
和谐拯救危机
Agree with them.
Just guessing: if proc means automatically picks up the format of permno, is it possible for its output giving a different type of permno with the original one?&&Of course, it is possible only if permno is numeric in data two that actually originates from data one.
谢谢各位的答案,我先试试看
三人行,必有我师焉;择其善者而从之,其不善者而改之
初级学术勋章
初级学术勋章
初级热心勋章
初级热心勋章
初级信用勋章
初级信用勋章
中级热心勋章
中级热心勋章
中级学术勋章
中级学术勋章
中级信用勋章
中级信用勋章
高级热心勋章
高级热心勋章
高级学术勋章
高级学术勋章
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
如有投资本站或合作意向,请联系(010-);
邮箱:service@pinggu.org
投诉或不良信息处理:(010-)
论坛法律顾问:王进律师在SAS中怎么批量地将数值型转化为字符型_百度知道
在SAS中怎么批量地将数值型转化为字符型
我有更好的答案
/*The macro system option SYMBOLGEN is set to be able to see what the macro*/&#47sas官网的例子;, :n_list separated by '=&#39,
trim(left(newname))||'
select trim(left(name)), trim(left(newname));
AAA 50 11 1 222 22
BBB 35 12 2 250 25
CCC 75 13 3 990 99
/*PROC CONTENTS is used to create an output data set called VARS to list all *//
input id $ b c $ d e $
*appended to /*variable and each character variable separated by an equal sign to be used on*/ /*the RENAME statement.
/*variables and exclude the one ID*last macro variable named renam_list will contain a list of each new numeric */;
newname=trim(left(name))||&
data vars.
*//*contain a list of each new numeric variable separated by a blank space.
The *//*separa*PROC SQL is used to create three macro variables with the INTO clause.
The next macro variable named n_list will
*//*macro variable named c_list will contain a list of each character variable
*/*variable names and their type from the TEST*variables resolved to in the SAS_n& '
proc contents data=test out=vars(keep=name type)
A new list of numeric*/ /*variable names is created from the character variable name with a &*A DATA step is used to subset the VARS data set to keep only the character *&#47.
*/data test。/*The sample data set TEST contains both character and numeric variables*&#47:它是将数据中所有的字符型转变为数值型,相应变化下就可以解决你的问题;
if type=2 and name ne 'id',
:renam_list separated by ' '
/*The DATA step is used to convert the numeric values to character.
*//*statement is used for the list of character variables and another ARRAY for
*//*the list of numeric variables.
A DO loop is used to process each variable
*//*to convert the value from character to numeric with the INPUT function.
The *//*DROP statement is used to prevent the character variables from being written *//*to the output data set, and the RENAME statement is used to rename the new
*//*numeric variable names back to the original character variable names.
data test2;
array ch(*) $ &c_
array nu(*) &n_
do i = 1 to dim(ch);
nu(i)=input(ch(i),8.);
drop i &c_
rename &renam_
;||trim(left(name))
into :c_list separated by ' &#39
有没有更简单的方法,这个到后面的话,就看不太懂了,我想是不是可以直接用数组的形式批量修改呢,而且上面的这个程序好像是批量地将字符型转化为数值型
这个代码是更一般的,它的原理和你想的一样,利用数组批量更改。你只需要根据这个代码进行character和numeric变量进行变换下就行了。
采纳率:73%
为您推荐:
其他类似问题
您可能关注的内容
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。SAS 复习_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
阅读已结束,下载本文需要
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,同时保存到云知识,更方便管理
还剩20页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢}

我要回帖

更多关于 sas 改变变量顺序 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信