全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1616 5
2015-08-26
我用sas base 写code很长时间了,一直以来有个疑问:

曾经在写比较复杂的code的时候,特别是迭代层数比较多的code,譬如中间穿插了很多外部的code文件,经常会遇到code执行不了的情况,
详细检查发现code没有任何问题,但sas总是报错,不是找不到某个file就是无法定义一些变量,而单独选定提交相应的code(而非整个code)就完全可以执行,
或者只要改写coding的方式,减少迭代,甚至是按submit的那个键的力度不同,code都可以正确执行,但这样却降低了效率

我试想是不是sas base这个compilier比较弱,一旦code比较负责就容易出问题?不知大家有没有遇到过,都怎样解决的?
二维码

扫码加我 拉你入群

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

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

全部回复
2015-8-27 00:33:59
kofsphere 发表于 2015-8-26 21:16
我用sas base 写code很长时间了,一直以来有个疑问:

曾经在写比较复杂的code的时候,特别是迭代层数比较 ...
请举个例子
二维码

扫码加我 拉你入群

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

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

2015-8-27 08:51:48
“按submit键力度不同,会影响code的执行”? SAS应该没那么大脾气。
具体原因应该还是在代码里,比如很多外部code文件的执行顺序会不会影响执行结果?
二维码

扫码加我 拉你入群

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

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

2015-8-27 13:26:15
我以为是我打开这个贴的方式不对,

直到我看到了:按submit键力度不同..

兄台再运行几段程序可以和SAS无障碍对话了

code比较复杂,多次循环,可以考虑是否某次循环某个数据集本身没有生成,但是拿上一次循环留下来的数据集直接调用了。

编译出错,干脆把里面全部注释手动删除看一下运行效果。
二维码

扫码加我 拉你入群

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

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

2015-8-30 07:17:00
那么举个例子,请大家看这个例子
下面是code

* code A ;
* ignore detailed logs ;
options nosource nonotes pagesize= max ;
* output 'warnings' in the log to an external file ;
*proc printto log='H:\SAS output log\SAS_log';
run;

*proc printto  ; run;

* load external macros ;
%include 'H:\External macros\code x count rows and columns.sas' ;run ;

* define the category we want to model and its library  ;
%let raw_data = data5.Data_factor ;
%let category = king ;

* define intermediate libraries which stores the retained variables by the two-stage vsm ;
%let dest_lib1= data_var ;
%let dest_lib2= data_v2 ;

* input the number of rolling events ;
%let experiment= 1 ;  
%put &experiment &raw_data &category ;
上面的code调用了一个外部的文件,叫做code x count rows and columns.sas,这个外部的macro function是用来找出一个data table里面的行数和列数的(非常有用,如果大家觉得有价值可以收藏),里面包含:


%macro obsnvars(ds);
%global dset nvars nobs;
%let dset=&ds;

/* Open data set passed as the macro parameter */
%let dsid = %sysfunc(open(&dset));

/* If the data set exists, then grab the number of observations and variables */
/* then close the data set                                                    */
%if &dsid %then
   %do;
      %let nobs =%sysfunc(attrn(&dsid,nobs));
      %let nvars=%sysfunc(attrn(&dsid,nvars));
      %let rc = %sysfunc(close(&dsid));
   %end;

/* Otherwise, write a message that the data set could not be opened */
%else %put open for data set &dset failed - %sysfunc(sysmsg());
%mend obsnvars;


/* Execute the macro -- pass TEST as the data set parameter

%obsnvars(test)
* /
* %put &dset has &nvars variable(s) and &nobs observation(s).;


现在的问题是,code A是无法运行的, 然而只要不调用这个外部文件就可以运行
请各位用自己的系统试试看
二维码

扫码加我 拉你入群

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

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

2015-8-30 07:45:40
终于找到问题所在!
解决了长久以来困扰我的问题!

在一个macro里面,注释语句一定要用/*   xxx  */ 而不是 * xxx  ; 后者无法将macro内部的%识别为comment

最后,谢谢大家!
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群