楼主: lovedieer
2193 14

[问答] 请帮忙改写一个SAS程序 [推广有奖]

  • 0关注
  • 1粉丝

硕士生

60%

还不是VIP/贵宾

-

威望
0
论坛币
11 个
通用积分
2.0724
学术水平
1 点
热心指数
1 点
信用等级
1 点
经验
17239 点
帖子
146
精华
0
在线时间
201 小时
注册时间
2009-4-22
最后登录
2022-9-12

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
我现在有一个SAS程序,一共有20个问题(Q1-Q20), 每个问题的基本程序都一样,只有两处不同,第一就是每个问题都有一个不同的TITLE, 譬如说 对于Q1: TITLE"Q1:WHAT IS YOUR NAME", 对于Q2 :TITLE "Q2:WHAT IS YOUR DOB"等等。第二个不同就是把程序里的Q1变成Q2,Q3。。。。。

我只会把同样的程序复制20遍,然后改一下里面的TITLE内容并且把Q1什么的带换一下。如果需要修改某部分程序,要修改20次才行,
  1. Title5 h=10pt "Q1)  Process: What is your Name";
  2. proc sql;
  3. create table loc_Q1 as
  4. select distinct upcase(Target)as Target, Region, reviewtype,
  5. sum(Q1='Yes' or Q1='No') as total , sum(Q1='Yes') as yes_count, calculated yes_count / calculated total as per format=percent9.2
  6. from sasuser.Demo
  7. where Target Contains "&Target" and input("&FromDate.",mmddyy10.)<= (sigDate)<=input ("&todate.",mmddyy10.)
  8. group by Region, reviewtype; quit;

  9. proc report nowd data=loc_Q1;
  10. column Region region_name reviewtype,(yes_count total Percentage)
  11. ("Region Total" Region_yes Region_all Region_per);
  12. define Region /group 'Region' noprint;
  13. define region_name /computed 'Region';
  14. define reviewtype / 'Review Type' across;
  15. define yes_count/analysis 'Yes Number';
  16. define total/analysis 'Total Number';
  17. define percentage/computed "Percentage" format=percent8.2;
  18. define Region_yes/computed "YES Number"   ;
  19. define Region_all/"Total Number" Computed;
  20. define region_per/computed "Percentage" format=percent8.2;

  21.    compute region_name /char; region_name=Region;if region_name='' then region_name='Total';endcomp;
  22.    compute percentage;   _c5_ = _c3_/_c4_;   _c8_= _c6_/_c7_;   endcomp;
  23.    compute Region_yes ;Region_yes= sum(_c3_ ,_c6_);endcomp;
  24.    compute Region_all;Region_all=sum(_c4_,_c7_);endcomp;
  25.    compute Region_per;region_per=_c9_/_c10_;endcomp;
  26. rbreak after /summarize ;
  27. run;
复制代码

请高手帮我精简一下程序。
二维码

扫码加我 拉你入群

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

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

关键词:sas程序 calculate proc sql Distinct sasuser 程序

15
lovedieer 发表于 2013-3-13 22:38:43 |只看作者 |坛友微信交流群
I am learning Macro now, and just learned that call symputx which added for SAS9.1 and later can used to remove all the spaces. I tried and it works.

使用道具

14
yongyitian 发表于 2013-3-13 12:40:28 |只看作者 |坛友微信交流群
Eternal0601 发表于 2013-3-13 10:18
Sorry. The previous explanation was not the key.

The real problem is caused by   call symput(' ...
You are right. Thanks for let me know that.
Acturally, I found the number in the title strange, so I removed &num in the saved code. That is why I did not found the message at second run.

使用道具

13
Eternal0601 发表于 2013-3-13 10:18:54 |只看作者 |坛友微信交流群
yongyitian 发表于 2013-3-13 01:18
It is good you made it works. I am still not sure why tiele&num got a warning.  It is seems that t ...
Sorry. The previous explanation was not the key.

The real problem is caused by   call symput('num', num); The numeric values have been converted to character values. In the case, SAS will automatically add several spaces before the num value.

When you replace it with call symput('num', put(num,1.)), there is no warning in the log window.

使用道具

12
lovedieer 发表于 2013-3-13 03:20:46 |只看作者 |坛友微信交流群
I do not have any warning error. somebody else try the program.  I think his problem is there's space between title and &num.  From his log, title1 was transfer to " title    1".

使用道具

11
yongyitian 发表于 2013-3-13 01:18:29 |只看作者 |坛友微信交流群
lovedieer 发表于 2013-3-13 00:57
I did several modification with your code to fit my program. and it works great. Thank you very much ...
It is good you made it works. I am still not sure why tiele&num got a warning.  It is seems that the title does not need a numer in your case.

使用道具

10
lovedieer 发表于 2013-3-13 00:57:55 |只看作者 |坛友微信交流群
I did several modification with your code to fit my program. and it works great. Thank you very much.

使用道具

9
Eternal0601 发表于 2013-3-12 23:25:02 |只看作者 |坛友微信交流群
yongyitian 发表于 2013-3-12 22:51
I run the code again, did not see any warning message. But the title is not shown in the html outp ...
I got it. &num in the title statement will be returned as '1'  '2'  '3', which cause the warning in the log window. After removing &num in the statement, there is no such error.

http://listserv.uga.edu/cgi-bin/ ... ;L=sas-l&P=2440

使用道具

8
Eternal0601 发表于 2013-3-12 22:57:17 |只看作者 |坛友微信交流群
yongyitian 发表于 2013-3-12 22:51
I run the code again, did not see any warning message. But the title is not shown in the html outp ...
NOTE: CALL EXECUTE generated line.
1   + title           1 h=10pct "Q1   Process: What is your Name                        ";
WARNING: The TITLE statement is ambiguous due to invalid options or unquoted text.
1   +                                                                                            proc
print data=a;           run;

NOTE: There were 3 observations read from the data set WORK.A.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.32 seconds
      cpu time            0.03 seconds


2   + title           2 h=10pct "Q2   Process: what is your city                        ";
WARNING: The TITLE statement is ambiguous due to invalid options or unquoted text.
2   +                                                                                            proc
print data=a;           run;

NOTE: There were 3 observations read from the data set WORK.A.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


3   + title           3 h=10pct "Q3   Process: what is your address                     ";
WARNING: The TITLE statement is ambiguous due to invalid options or unquoted text.
3   +                                                                                            proc
print data=a;           run;

NOTE: There were 3 observations read from the data set WORK.A.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds



使用道具

7
yongyitian 发表于 2013-3-12 22:51:49 |只看作者 |坛友微信交流群
Eternal0601 发表于 2013-3-12 22:31
Great. And I wonder if there is any method to eliminate the warning about the title statement in t ...
I run the code again, did not see any warning message. But the title is not shown in the html output window. I don't know why. What is warning you got?

使用道具

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

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

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

GMT+8, 2024-5-22 06:21