楼主: 龙潭丰乐
1365 7

提取字符 [推广有奖]

  • 14关注
  • 4粉丝

已卖:115份资源

讲师

50%

还不是VIP/贵宾

-

威望
0
论坛币
6 个
通用积分
0.0600
学术水平
25 点
热心指数
29 点
信用等级
14 点
经验
8649 点
帖子
457
精华
0
在线时间
466 小时
注册时间
2011-11-20
最后登录
2022-1-6

楼主
龙潭丰乐 学生认证  发表于 2012-11-15 19:19:50 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
course变量含有如下值:
HIST400
SCI400
MATH400
怎么把它变成两个变量SUBJECT 、 LEVEL
hist   400
sci    400
math 400

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Subject Course Level hist Math course

已有 1 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
Imasasor + 12 + 12 + 1 + 1 + 1 鼓励积极发帖讨论

总评分: 经验 + 12  论坛币 + 12  学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

沙发
Imasasor 发表于 2012-11-15 20:36:10
使用compress函数,compress(variable,"","modifier"),modifier可以使用k,表示保留,用d表示数字,kd表示只保留数字
如level=compress(course,"","kd");
同样有一个modifier表示字母,具体我忘了,你可以查一下,
要么就是subj=compress(course,"0123456789");
欢迎加入亚太地区第一R&Python数据挖掘群: 251548215;

藤椅
龙潭丰乐 学生认证  发表于 2012-11-15 20:59:00
level=substr(course,length(course)-2,3);
SUBJECT=substr(course,1,length(course)-3);

板凳
webgu 发表于 2012-11-15 21:40:18
  1. data raw;
  2. x='HIST400';output;
  3. x='SCI400';output;
  4. x='MATH400';output;
  5. run;
  6. data  out(drop=x);
  7. set raw;
  8.    subject=compress(x,,'ka');output;
  9.    level=compress(x,,'kd');output;
  10. run;
复制代码
IMASASOR说的应该是这个。
SAS资源
1. SAS 微信:StatsThinking
2. SAS QQ群:348941365

报纸
bobguy 发表于 2012-11-16 11:54:23
It is better to use function to identify the positions and handle it accordingly. Keep in mind to minimize the assumptions about data structures.

data def;
length subject level $15;
input x $20.;
subject=substr(x,1,indexc(x,'0123456789')-1) ;
level  =substr(x,indexc(x,'0123456789')) ;
cards;
HIST400
SCI400
MATH400
HIST400
LANGUAGE12345
;

proc print;run;

地板
龙潭丰乐 学生认证  发表于 2012-11-19 23:47:18
compress(character-value,<,'compress-list'>,<,modifiers>)
其中modifiers有:
a include all upper and lowercase letter
d include all digits
i ignore the case of character
还有 k p s

7
龙潭丰乐 学生认证  发表于 2012-12-2 19:57:57
bobguy 发表于 2012-11-16 11:54
It is better to use function to identify the positions and handle it accordingly. Keep in mind to mi ...
想请问,这个用正则表达式怎么弄?

8
老师她摸我 发表于 2012-12-2 21:48:10
龙潭丰乐 发表于 2012-12-2 19:57
想请问,这个用正则表达式怎么弄?
正则表达式:
  1. data test(drop=course);
  2.         input course $;
  3.         SUBJECT=put(prxchange("s/[0-9]/ /",-1,course),8.);
  4.         LEVEL=input(prxchange("s/[^0-9]/ /",-1,course),best12.);
  5.         cards;
  6. HIST400
  7. SCI400
  8. MATH400
  9. ;
  10. run;
复制代码

欢迎加入SAS群:144839730-蜗牛

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-27 06:17