楼主: ywu0212
1999 11

[问答] 急求各位大神一个MACRO 关于数据扫描,提取的问题? 多谢 [推广有奖]

  • 0关注
  • 0粉丝

高中生

85%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
257 点
帖子
24
精华
0
在线时间
40 小时
注册时间
2013-9-17
最后登录
2017-4-29

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币

谢谢各位大神了,真的是没有一点想法啊。感谢

Input requirement:

Write a macro called XSCAN which has 3 positional parameters:

· STRING – A text string containing a list of words.

· DELIMITER – A single character used to separate the words in STRING.

· WORD_NUMBER-An integer specifying the Nth word in STRING.  If the value is positive, count from the left of the string.  If the value is negative, count backward from the right of the string.

Processing requirement:

Derive the substring of STRING which starts with the Nth word in STRING, as described in the WORD_NUMBER parameter above.

Output

The substring should be printed to the SAS Log when the macro is called.

Examples:

Call

%xscan(a bb ccc dddd bb eeeee, %str( ), 1)

Result

a bb ccc dddd bb eeeee

二维码

扫码加我 拉你入群

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

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

关键词:Macro Mac CRO acr Requirement character positive backward separate called

沙发
Imasasor 发表于 2013-10-11 10:00:20 |只看作者 |坛友微信交流群
例子跟要求不符啊,位置为1时,第1st word 就是a啊,怎么会出来那个结果?
欢迎加入亚太地区第一R&Python数据挖掘群: 251548215;

使用道具

藤椅
ywu0212 发表于 2013-10-11 10:04:50 |只看作者 |坛友微信交流群
谢谢啊,
再多两个例子,这样清楚点了么
Call               
%xscan(%str(a,bb,ccc,dddd,bb,eeeee), %str(,), 3)
Result               
ccc,dddd,bb,eeeee

Call               
%xscan(a bb ccc dddd bb eeeee, %str( ), -2)
Result               
bb eeeee

使用道具

板凳
Imasasor 发表于 2013-10-11 10:43:02 |只看作者 |坛友微信交流群
  1. %macro xscan(string=,str=,position=);
  2. %let n=%eval(%sysfunc(count(&string,&str))+1);
  3. %let final=;
  4. %if &position<0 %then %do;
  5. %let position=%eval(&n+1&position);
  6. %end;
  7. %do i=&position %to &n;
  8. %let string&i=%scan(&string,&i,&str);
  9. %if &i=&position %then %do;
  10. %let final=&&string&i;
  11. %end;
  12. %else %do;
  13. %let final=&final.&str.&&string&i;
  14. %end;
  15. %end;
  16. %put &final;
  17. %mend;
  18. %xscan(string=%str(a,bb,ccc,dddd,bb,eeeee),str=%str(,),position=-1)
复制代码
好吧, 哥承认自己写的很麻烦,如果你认为对你有所帮助的话,请在右下角评分中给我加几分吧
已有 2 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
admin_kefu + 100 热心帮助其他会员
ywu0212 + 1 + 1 + 1 观点有启发

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

欢迎加入亚太地区第一R&Python数据挖掘群: 251548215;

使用道具

报纸
ywu0212 发表于 2013-10-11 11:21:15 |只看作者 |坛友微信交流群
Imasasor 发表于 2013-10-11 10:43
好吧, 哥承认自己写的很麻烦,如果你认为对你有所帮助的话,请在右下角评分中给我加几分吧
太感谢了!评分有点少吧,真不好意思

使用道具

地板
_i_ 发表于 2013-10-11 12:55:26 |只看作者 |坛友微信交流群
Imasasor 发表于 2013-10-11 10:43
好吧, 哥承认自己写的很麻烦,如果你认为对你有所帮助的话,请在右下角评分中给我加几分吧
好 想评分竟然不能

使用道具

7
ywu0212 发表于 2013-10-11 15:22:43 |只看作者 |坛友微信交流群
Imasasor 发表于 2013-10-11 10:43
好吧, 哥承认自己写的很麻烦,如果你认为对你有所帮助的话,请在右下角评分中给我加几分吧
再请问一下怎样用啊,要到下面这样的效果(The substring should be returned as a value when the macro is called.)万分感谢!
Examples:
Call               
%let sub_str = %xscan(a bb ccc dddd bb eeeee, %str( ), -2);
%put The value of sub_str = &sub_str;
Result               
The value of sub_str = bb eeeee

使用道具

8
Imasasor 发表于 2013-10-11 16:53:11 |只看作者 |坛友微信交流群
在宏中加上这句话就行了:%put The value of sub_str = &sub_str;
欢迎加入亚太地区第一R&Python数据挖掘群: 251548215;

使用道具

9
邓贵大 发表于 2013-10-11 20:16:43 |只看作者 |坛友微信交流群
how about %sysfunc(scan(a bb ccc ddd bb eeeee, -2, %str( ))) since %sysfunc was used anyway?
Be still, my soul: the hour is hastening on
When we shall be forever with the Lord.
When disappointment, grief and fear are gone,
Sorrow forgot, love's purest joys restored.

使用道具

10
ywu0212 发表于 2013-10-11 21:26:44 |只看作者 |坛友微信交流群
Imasasor 发表于 2013-10-11 16:53
在宏中加上这句话就行了:%put The value of sub_str = &sub_str;
加哪啊?能麻烦放在例子里么,谢谢!
觉得自己智商无下限啊,崩溃了!

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-30 17:01