SAS中文论坛

标题: 请高手看看宏程序里面的条件语句为什么不能跳转? [打印本页]

作者: shiyiming    时间: 2011-12-6 17:58
标题: 请高手看看宏程序里面的条件语句为什么不能跳转?
%macro lab1;
%if %sysfunc(exist(labo)) ne 0 %then %do;
proc datasets lib=work nolist;
  delete labo;
quit;
%end;
%do i= 1 %to 9;
data labout;
  set dog;
  where zc10&i. in(2,3) or zc70&i. in(2,3) or zc90&i. in(2,3) or zc130&i. in(2,3) or zch&i. in(2,3) ;
  typevar=lab10&i.;
  if vtype(typevar)="N"  then do;
  lab1 =put(lab10&i.,best.);
  lab7 =put(lab70&i.,best.);
  lab9 =put(lab90&i.,best.);
  lab13 =put(lab130&i.,best.);
  labh =put(labh&i.,best.);
  end;
  else do;
  lab1 =lab10&i.;
  lab7 =lab70&i.;
  lab9 =lab90&i.;
  lab13 =lab130&i.;
  labh =labh&i.;
  end;
  rename  zc10&i.=zc1 zc70&i.=zc7 zc90&i.=zc9 zc130&i.=zc13 zch&i.=zch;
  name=&i.;
run;
data laboo;
  length lab1  lab7  lab9  lab13  labh  $60.;
  set labout;
  keep no group treat_  name lab1 zc1 lab7 zc7 lab9 zc9 lab13 zc13 labh zch;
run;
proc append base=labo data=laboo force;run;
%end;
%mend;
option mprint ;
%lab1
如果typevar是字符型的话,应该运行这里:
  lab1 =lab10&i.;
  lab7 =lab70&i.;
  lab9 =lab90&i.;
  lab13 =lab130&i.;
  labh =labh&i.;
但是事实上没有。。。所以就出现错误
作者: shiyiming    时间: 2011-12-7 10:28
标题: Re: 请高手看看宏程序里面的条件语句为什么不能跳转?
something wrong about using put funciton.
you can consider the ways like the following:

1.
typevar=lab101;
if vtype(typevar)="N" then do;
lab1 =putn(lab101,'best.');...
; else lab1 =lab101;
....
2.
in fact, in your case the cats() also works in a very elegant way:
lab1 =cats(lab101); *regardless of whatever type of lab101;

I did not know how come put() not working here: it looks like put() was verified in advance; and I met with the exact problem months ago.
Jingju
作者: shiyiming    时间: 2011-12-7 16:26
标题: Re: 请高手看看宏程序里面的条件语句为什么不能跳转?
cats  thanks!




欢迎光临 SAS中文论坛 (https://www.mysas.net/forum/) Powered by Discuz! X3.2