楼主: moshushi8928
7035 13

请教各位朋友有关sas list的问题 [推广有奖]

  • 4关注
  • 1粉丝

高中生

55%

还不是VIP/贵宾

-

威望
0
论坛币
3 个
通用积分
0
学术水平
5 点
热心指数
5 点
信用等级
5 点
经验
124 点
帖子
13
精华
0
在线时间
39 小时
注册时间
2011-12-7
最后登录
2021-12-15

楼主
moshushi8928 发表于 2013-6-11 06:40:52 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
想编出一个提取数据的宏,filed 是变量名, list是我们想要的值,dsin和dsout分别是input 和output, 代码很简单,如下:
%macro
ExtractICD9(field, list, dsin, dsout);
proc sql;
create table &dsout as
select * from &dsin
where &field in &list;
quit;
%mend ExtractICD9;
现在有3个问题:(1)如果field取值超过了1, 变成了一个list,如(a,b,c),那么代码就不能运行了……(2)如果list中的值很多,储存在一个txt文件中,不便于一个一个输入,能做到直接读取txt文件得到list的值吗?也就是说此代码中的宏变量由list变成了path(txt文件的路径)。(3)txt中的list值,很可能出现类似433x1的情况,意味着我们要找43301, 43311, 43321,43331,43341,43351,43361,43371,43381,43391,即x意味着所有0-9取值。这三个SAS问题感觉都比较难,而且不是很常见,大家对其中任意一个有想法也请发表宝贵意见,在下不胜感谢。

二维码

扫码加我 拉你入群

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

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

关键词:list IST proc sql extract Create create field where

已有 1 人评分学术水平 热心指数 信用等级 收起 理由
jingju11 + 5 + 5 + 5 精彩的问题

总评分: 学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

沙发
邓贵大 发表于 2013-6-11 10:23:03
嗯,确实比较难!
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.

藤椅
boe 发表于 2013-6-11 11:20:04
在data步中用array应该可以吧,list的值如果全部在txt文件里的话,先处理一下。。。
Gorgeous girl , I love !

板凳
yuerqieqie 发表于 2013-6-11 22:04:16
问题1和3是可以解决的,就是麻烦一点儿
  1. %macro ExtractICD9(field, list, dsin, dsout);

  2.         %local k n_var;
  3.         proc contents data = &dsin(keep = &field) out = _var(keep = varnum name) noprint; run;
  4.         data _null_;
  5.                 set _var end = eof;
  6.                 call symput(compress("var"||_n_), name);
  7.                 if (eof) then call symput('n_var', compress(_n_)); run;

  8.         %local list_tran;
  9.         %let list_tran = %sysfunc(tranwrd(%upcase(&list), %upcase(x), _));

  10.         %local j n_list;
  11.         %let j = 1; %let listVar&j = %scan(&list_tran, &j, %str( ));
  12.         %do %while (&&listVar&j ne %str());
  13.                 %put &&listVar&j;
  14.                 %let j = %eval(&j + 1); %let listVar&j = %scan(&list_tran, &j);
  15.         %end;
  16.         %let n_list = %eval(&j - 1);

  17.         %if %index(&list_tran, _) %then %do;
  18.                 proc sql;
  19.                         create table &dsout as
  20.                         select * from &dsin
  21.                         where 0 %do k = 1 %to &n_var; or (0 %do j = 1 %to &n_list; or (&&var&k like &&listVar&j) %end;) %end;;
  22.                 quit;
  23.         %end;
  24.         %else %do;
  25.                 proc sql;
  26.                         create table &dsout as
  27.                         select * from &dsin
  28.                         where 0 %do k = 1 %to &n_var; or &&var&k in (&list) %end;;
  29.                 quit;
  30.         %end;
  31. %mend ExtractICD9;
  32. %ExtractICD9(Dx1 Dx2, '340' '433x1', in, test)
复制代码
问题2的话觉得在macro外import成data,然后生成macro变量。

总之,觉得很麻烦,不知道有没有简单的方法
已有 2 人评分学术水平 热心指数 信用等级 收起 理由
jingju11 + 5 + 5 + 5 精彩帖子
boe + 1 + 1 + 1 精彩帖子

总评分: 学术水平 + 6  热心指数 + 6  信用等级 + 6   查看全部评分

报纸
boe 发表于 2013-6-12 00:51:41
个人理解,不知合不合要求,很多细节没处理好,多多指教。。。 (list。txt里面的值是4、5、6)。。。
  1. data test;
  2.     input x1-x10;
  3. datalines;
  4. 1 1 2 2 3 3 4 4 5 5
  5. 2 2 3 3 4 4 5 5 6 6
  6. 3 3 4 4 5 5 6 6 7 7
  7. 4 4 5 5 6 6 7 7 8 8
  8. 5 5 6 6 7 7 8 8 9 9
  9. 6 6 7 7 8 8 9 9 0 0
  10. ;
  11. run;
  12. %macro ExtractICD9(field,path,dsin,dsout);
  13. data _null_;
  14.     infile "'&path'";
  15.     input;
  16.         length list $100.;
  17.         retain list;
  18.         list=catx(" ",list,_infile_);
  19.         put list=;
  20.         call symput('list',list);
  21. run;
  22. %put &list;

  23. data &dsout;
  24.     set &dsin;
  25.         array field &field;
  26.         do over field;
  27.             if field in (&list);
  28.         end;
  29. run;
  30. %mend ExtractICD9;
  31. %ExtractICD9(x3 x4,g:\list.txt,test,need)
复制代码
已有 2 人评分学术水平 热心指数 信用等级 收起 理由
yuerqieqie + 1 + 1 + 1 观点有启发
jingju11 + 5 + 5 + 5 精彩帖子

总评分: 学术水平 + 6  热心指数 + 6  信用等级 + 6   查看全部评分

Gorgeous girl , I love !

地板
邓贵大 发表于 2013-6-12 02:46:03
ICD-9 diagnosis code are usually between 3 to 5 characters (most are digits), so don't go beyond 5 digits guys. http://www.icd9data.com/2013/Volume1/default.htm
As I recall, University of Manitoba has some sample code here (not great but a good start for the OP)
http://mchp-appserv.cpe.umanitob ... .php?conceptID=1098

OP's question (1) and (2) have already been very well addressed by Board Of Education and yuerqieie. But usually the complete list of ICD-9 codes are not given for a certain disease or condition. For example, your boss may say drug dependency is identified by 304.xx. Do you really want to go through the ICD-9 code book to create yourself a complete list of 5-digit subcodes and write them into a text file, or you'd rather match the first 3 digits only? Also the DX code in your patient database may not be entered as specific as 5 digits, so you have to put the parent code in your list as well. Question (3) is rather simple, you may put
  1. substr(dx,1,4) between "4330" and "4339" and substr(dx,5,1)="1"
复制代码
My point is, you cannot go 100% precise for the subject. I'd rather sacrifice accuracy by using the Manitoba approach so I can sleep better.
已有 2 人评分学术水平 热心指数 信用等级 收起 理由
yuerqieqie + 1 + 1 + 1 好的意见建议
jingju11 + 5 + 5 + 5 精彩帖子

总评分: 学术水平 + 6  热心指数 + 6  信用等级 + 6   查看全部评分

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.

7
moshushi8928 发表于 2013-6-12 10:41:49
yuerqieqie 发表于 2013-6-11 22:04
问题1和3是可以解决的,就是麻烦一点儿问题2的话觉得在macro外import成data,然后生成macro变量。

总之, ...
强!不过code有处看不懂,where 0 %do k = 1 %to &n_var; or (0 %do j = 1 %to &n_list; or (&&var&k like &&listVar&j) %end;) %end;; 我知道这是在数据集中,寻找list里带x的数值,但不清楚为什么这样写,能逐句解释一下吗?还有最后那个end,为什么后面两个分号呢?先谢谢了

8
moshushi8928 发表于 2013-6-12 10:47:20
boe 发表于 2013-6-12 00:51
个人理解,不知合不合要求,很多细节没处理好,多多指教。。。 (list。txt里面的值是4、5、6)。。。
多谢,do over语句用的非常精妙,长姿势了:)

9
jingju11 发表于 2013-6-12 10:59:12
的确是高水平之间的探讨。(虽然我是题目都没有完全理解。)。现在才意识到sas可以做这么多的东西。。。京剧

10
boe 发表于 2013-6-12 11:04:15
如果每个dsin对应一个txt的话,这样做没有问题,可能input x@;
如果多个dsin对应一个txt的话,需要进一步做相应的选择。。。。。
Gorgeous girl , I love !

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

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