sas - 将字符串中包含句点的缩写替换为 SAS 中没有句点的缩写
问题描述
我有以下数据集,如果它是“MD”或“MD”或“MD”,我想替换最后一个单词。与“MD”。
DATA EXAMPLE1;
INPUT Names $char30.;
DATALINES;
AARON RAY, M.D.
AARON,RAY MD.
RAY,AARON,M.D.
PMD RAY ARON M.D
AARON MD RAY
AARON RAY
;
run;
Data Convert;
Set Example1;
*I have used the following codes to address the different formats;
if scan(Names,-1,' ')=' MD. ' then Name_temp=tranwrd(Names,' MD. ',' MD ');
if scan(Names,-1,' ')=' M.D. ' then Name_temp=tranwrd(Names,' M.D. ',' MD ');
if scan(Names,-1,' ')='M.D.' then Name_temp=tranwrd(Names,'M.D.','MD');
if scan(Names,-1,' ')=',M.D.' then Name_temp=tranwrd(Names,',M.D.',' MD ');
if scan(Names,-1,' ')=' M.D.' then Name_temp=tranwrd(Names,' M.D.',' MD ');
if scan(Names,-1,' ')=' M.D ' then Name_temp=tranwrd(Names,' M.D ',' MD ');
run;
但只有名字被转换。
让我知道我能做些什么来得到这个输出
Obs Names Name_temp
1 AARON RAY, M.D. AARON RAY, MD
2 AARON,RAY MD. AARON RAY, MD
3 RAY,AARON,M.D. AARON RAY, MD
4 PMD RAY ARON M.D AARON RAY, MD
5 AARON MD RAY
6 AARON RAY
解决方案
与其搜索所有可能的MD
拼写方式,不如将最后一个单词标准化MD
并搜索它。
data want;
set example1;
last_word = scan(names, -1, ', ');
if(compress(last_word, '. ') = 'MD')
then name_temp = tranwrd(names, strip(last_word), 'MD');
run;
推荐阅读
- azure-devops - 当单元测试项目引用函数项目时,Azure 函数构建管道失败
- javascript - 在 Highcharts 的国家图表中使用 MapBubble
- r - 是否可以获得较低精度的路径长度?
- java - Kafka、Quarkus 和 Avro 在同一主题中的几种事件类型
- laravel-7 - 用户首次在 Laravel 7 中注册后如何重定向到动态路由
- jmeter - 我们可以停止 JMeter 负载测试自动停止吗
- angular - 角度请求返回 NET::ERR_CERT_AUTHORITY_INVALID
- java - java中小型静态数据集的内存自动完成实现
- javascript - 如何在不更改原始属性的情况下从角度 ReactiveForm 中删除属性?
- mysql - '字段列表'mysql中的未知列''