a********a 发帖数: 3176 | 1 Also, if used %do loop inside the macro, I got
'A character operand was found in the %EVAL function or %IF condition where
a numeric operand is required. The condition was:
timeline_length'
Otherwise, if I don't use macro, the simple do loop was alright (but can't
produce the output I want). What is happending here? |
|
a********a 发帖数: 3176 | 2 Thank you.
But timeline_length is not a macro variable - it is a regular var that has
values 1-300. How can I create a macro variable that has the same value? I
tried 'symget ' but it didn't work. |
|
p*********8 发帖数: 1039 | 3 帮忙看看
SAS programm
看了讲义,还是不太明白这个macro statement.
这 Macro 究竟干嘛用呢? |
|
g******n 发帖数: 339 | 4 Try
options mprint;
options mlogic;
to look at decoded SAS macros in the log first, then you will have an idea
of the macro.
If you are trying to step in a DATA step as you can do in other programming
enviorament, you can try the option debug. That is, put your data step
statement as
data XXX/debug;
they you can use many debug commands such as examine, step, list etc. to
step into the data step. |
|
s***b 发帖数: 192 | 5 工作中写过macro for iteration of independent variables or dependent
variables only. 现在想写一个macro for iteration of both dependent and
independent variables.
请问哪位牛人有sample code我可以借鉴一下。
另外,我的一个问题:
在这个情况下是否需要造两个_null_ datasets?
拜谢! |
|
a********a 发帖数: 3176 | 6 Thanks for having taken a look.
The macro was first written to assume that &site=site1 site2 ....site&n
consecutively.
And it later used do x=1 to &n.
Now I saw that sometimes it was &site=site1 site6 only, so 'do x=1 to 6'
doesn't work, and I'd like to make a macro variable that have value of 1 and
6 only, so that I can use 'do x=1,6'.
Does this make it cleaer?
Or is there any other way to get around this? |
|
q**j 发帖数: 10612 | 7 what is the difference between call execute and 'call symput' plus common
macro stuff? i can think of using n pairs of macro variables to save the
value and use a regular loop. what is the benefit of using call execute?
thanks a lot. |
|
d*******1 发帖数: 854 | 8 你这个datastep 和macro的loop 全搞混了.macro运用的最高境界就是"不用".
改如下:
%let covariates=age gender center EV1;
/*deleting records with missing covariates---complete obs only*/
data temp1;
set temp0;
if n (of &covariates)<4 then delete;
run; |
|
c********s 发帖数: 483 | 9 Do you mean label for variable name?
If you do not know how many variables on dataset
You may use 1>. sashelp to get variable name,
2>. Proc sql select into: to get macro list
3>. proc sql select n() to get count macro
4>. Using do loop or array to label variable using your label
rule.
|
|
f********m 发帖数: 197 | 10 Is it possible that you define two arrays, one store variable name, one
store newlabel,say
...
array varname{3} $ ('a' 'b' 'c');
array label_of_var{3} $ ('aaa','bbb','ccc');
...
Then you define the macro as
%macro labels (var_to_label=, label_of_var=);
...
label &var_to_label = &label_of_var;
...
%mend;
do i=1 to 3;
%labels(var_to_label=varname{i}, label_of_var=newlabel{i});
end;
May worth a shot. But I'm not sure if it will work. :) |
|
h*****5 发帖数: 14 | 11 谢谢大家。刚看了下,nlinmix macro只能用于正态分布。正在看proc GLIMMIX 和
macro,希望能work。
to hypnos: 太菜了,自己写不出gee code. 方便的话,能否借鉴一下?非常感谢。 |
|
j*****e 发帖数: 182 | 12 I have never used NLMIX macro. But I have used PROC NLMIX a lot. It is a
likelihood based approach, not GEE. You mentioned normal distribution. Are
you referrring to the random effectis treated normal? NLMIX can only
tolerate one random effect in the model. If you have multiple random effects
, you have to use GEE. Is NLMIX macro different from the PROC?
In general linear model, the random statement controls the design matrix and
the repeated statement control the residuals/sigma. In generalized |
|
h*****5 发帖数: 14 | 13 NLINMIX macro 可以fit gee model而proc nlmixed 不能。但NLINMIX macro只用于正
态分布,proc nlmixed 适用于更多的分布。
我已经proc nlmixed做了random effect zero-inflated model,现在想做gee model.找
不到现成的方法。 |
|
A*******s 发帖数: 3942 | 14 在首尾加上
%macro XXXXX;
%mend;
就变成macro了,哈哈 |
|
g********0 发帖数: 90 | 15 我知道有local,global来封装
可以看看sas advanced tutor
里面有专门讲怎么用这个。
macro |
|
h******e 发帖数: 1791 | 16 有一些macro variable,a1,a2,。。。。。,a10,有一个datase含10个observation
。如何利用_n_,将macro variable的值按顺序付给dataset中的一个variable?谢谢。 |
|
j*****7 发帖数: 4348 | 17 有没有可能assign一个普通variable的值到一个macro variable里面。
比如说这个data set:
NAME AGE
A1 23
A2 35
A3 33
...
用一个macro variable来代替AGE. |
|
A*******s 发帖数: 3942 | 18 1. Good to know that. How about datetime function?
Usually I use the value of a global macro var as the prefix of temporary
datasets and change it (++1) after each macro execution.
2. You mean string containing only blanks? SAS does have repeat function to
do that.
current |
|
s*******f 发帖数: 148 | 19 i'm trying to scan &syspbuff in order to assign the value to a macro
variable call &cc.
Usually i do it like this:
%macro m1 / parmbuff;
...
%let cc=%scan(&syspbuff,2);
...
%mend m1;
%m1(a,b,c,d,e)
Here &cc will be resolved to b.
But what if i would like to scan some strings with single quotes and commas?
such as:
%m1(%str('a','b','c')*%str('d','e'))
Here * is the delimiter (and i dunno if i treat it right with %str). I wanna
get the 'd','e' part as a whole from the scanning above.
I |
|
x***x 发帖数: 3401 | 20 The format for cityname has already been defined. What I wanna do now is
to modify the originally defined format, ie, remove some characters from
the originally defined value.
The macro shall look as simple as this:
%changeformat(var=cityname)
What the macro is supposed to do is:
1. Automatically determine the defined format for variable CITYNAME.
2. Modify the defined format, in this case: to remove the first 3
characters.
3. Attach the new format to variable CITYNAME.
e.g. No |
|
f*****u 发帖数: 129 | 21 想做这么一个简单的loop,但是总是出错,请大家指点一下问题在哪里,谢谢!
%macro test(min,max,jump);
%do x = &min %to &max %by &jump;
print x;
%end;
%mend;
%test(1,3,0.5);
ERROR: A character operand was found in the %EVAL function or %IF condition
where a numeric operand is required. The condition was: &jump
ERROR: The %BY value of the %DO X loop is invalid.
ERROR: The macro TEST will stop executing. |
|
f*****a 发帖数: 693 | 22 %macro test(min,max,jump);
%do x = &min %to &max %by &jump;
%let y=%sysevalf(&x-0.5);
%put &x &y;
%end;
%mend;
%test(1,3,1);
好像是sas macro 里的参数按字符处理,然后用%eval()来估值,但是%eval()只能估整
数值,所以你的0.5作为参数不行。但是我想在&min, &max, &jump前用上这个%
sysevalf()函数用来估值应该可以,但不知道为什么不行。我只好改成上面的方法,就
是参数里都是整数,在macro里再计算所需的指。还请高人指点能否有直接用参数
的方法。 |
|
h******e 发帖数: 1791 | 23 如何让word macro去读word 文件的内容,比如word里有“C:\my documents”,如何些代码让word macro读入这个路径?谢谢。 |
|
s********l 发帖数: 245 | 24 The reason behind that I have figured out, since I assign macro variable num
=100 then when I revoke the macro est, the following infile "path\data100
will execute. |
|
P****D 发帖数: 11146 | 25 You are right about that SAS procedure cannot be created by user. However, a
macro is just a bunch of procedures. It does not NECESSARILY help you
implement any logic.
I suggest you find a sample macro and a sample procedure and show them to
your LD. These two concepts are truly straightforward once you see examples,
but also impossible (I think) to explain just with words...
least
use |
|
a*****3 发帖数: 601 | 26 因为还在macro定义的domain之中吧? 可以试试跳出这个macro再来个 %put _user_. |
|
a*****3 发帖数: 601 | 27 "a DATA step that contains a SYMPUT routine within a macro definition"
说的是macro定义在data步里面吧? 不适用于你的这个例子吧? |
|
l*******s 发帖数: 437 | 28 %let startdate = 01-sep-09;
%let enddate = 31-aug-10;
PROC SQL;
connect to &co.;
CREATE table sc as
select *
from connection to oracle
(select *
from ops$dardev.sc_ref s
where start_date >= '01-jan-08' and start_date <= '31-aug-10'
and spec_dep_name in ('CA')
)
;
quit;
我试着用 where "&startdate."d <= datepart(start_date) <= "&enddate."d, 不
成功,但在这个程序中有其他地方用到这两个macro,例如:
proc means data=CA
(where=("&startdate."d <= datepart(start_date) <= "&enddate."d))
都是成功的。不知道问题出在哪?查了sta... 阅读全帖 |
|
s******y 发帖数: 352 | 29 Well,you need to mask the single quotation mark. as far as know, Oracle
requires you to surround the single quotation mark around the date string so
that it will be understood by Oracle.
But what if you want to pass a SAS macro variable via SAS/ACCESS pass-
through facility. then you need to first mask the single quotes to allow the
macro variable resolution. I don't have oracle connection now. you may need
to use To_date oracle function. i can not test it.
Please report back if it still doesn't... 阅读全帖 |
|
k*****u 发帖数: 1688 | 30 下面这组data,打算对列求和。 用data step可以如下做,现在打算把
sum1+summer1;
sum2+summer2;
sum3+summer3;
sum4+summer4;
换成用macro来改写,应该怎么写? 折腾了好久都没弄出来,求教。
我试着用array可以做,macro总是说有问题。谁能帮我写一下code? 谢谢
data wide;
input name $ summer1-summer4;
cards;
a 1 2 3 4
b 1 2 3 4
c 1 2 3 4
;
data sum_data;
set wide end=lastobs;
sum1+summer1;
sum2+summer2;
sum3+summer3;
sum4+summer4;
keep sum1-sum4;
if lastobs then output;
run;
proc print data=sum_data;
run; |
|
s******d 发帖数: 303 | 31 把经常要用的一个程序改成macro,叫GetInfor(Input=, Output=). 但是由于每次要读
入的文件不同,所以要赋予不同值给macro variable, 也就是这里的input and output.
现在的问题是,如果想要batch submission 这个 %GetInfor, 如果做?谢谢阿? |
|
G*******l 发帖数: 601 | 32 请问各位SAS 达人,如何在SAS 中加入他人写的MACRO,并让SAS 象使用其本身的MACRO
一样调用。 |
|
p*********8 发帖数: 1039 | 33 今天突然想到,其实macro 可能是个很好的将自己code打包整理的好工具
,大家有用macro打包整理自己的sas code吗? 我是在想,如果整理的好的话,
用起来应该效率比较高吧?有经验的tx能分享下吗? |
|
o****o 发帖数: 8077 | 34 then wrap it into a macro:
%macro switch(type);
%global s1 s2;
%if %upcase(&type) eq HTML %then %do;
%let s1=html;
%let s2=xls;
%end;
%else %if %upcase(&type) eq PDF %then %do;
%let s1=pdf;
%let s2=pdf;
%end;
%mend;
%switch(pdf);
ods listing close;
ods &s1 file="&add.\table.&s2";
options orientation=landscape nodate
nonumber missing=" " papersize="letter";
ods &s1 close;
ods listing; |
|
b****u 发帖数: 67 | 35 问题一
看不出毛病呀, 答案D也不work 呀?
85. Given the SAS data set OURDATA:
OURDATAObsproduct sales
1 OR 1000
2 NE 1200
3 MM 1450
After submitting a SAS program, the following is written to the SAS log:
70 %macro a;
71 data _null_;
72 set ourdata;
73 call symput('product'!!left(_n_), product);
74 run;
75 %if &product1 = OR %then %do;
76 proc means data = ourdata;
77 run;
78 %end;
79 %mend;
80 %a
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
73:66
NOTE: Th... 阅读全帖 |
|
d*******o 发帖数: 493 | 36 用一个macro不行吗?
%pearson(X, cycle = 1);
%do i=1 %to &cycle;
/**/
%end;
%mend;
nested macro涉及变量scope的问题。 |
|
A*******s 发帖数: 3942 | 37 嗯,我也猜有可能是这个原因。
比较好的风格是macro里定义的所有macro variabe都应该尽量是local的,最好避免用
太短的命名以免冲突。 |
|
D******n 发帖数: 2836 | 38 SAS Macro is different from function that is common in many other language.
Macros encapsulation is very bad. |
|
A*******s 发帖数: 3942 | 39 scopes of macro variables在advanced certificate就有说吧。有些细节要是自己没
用过肯定记不住。
我觉得,SAS这么笨的东西,就应该写的简单,写的复杂的都不可避免地要出错。而且想
想,比你水平差的同事都用了最笨的方法写完了,你还在辛辛苦苦殚精竭虑地debug一
个复杂的macro,划不来啊... |
|
p***r 发帖数: 920 | 40 just put the %windows statement in the iteration, and make some adjustment.
then everything is fine. I think this has things to do with the macro
facility and the scope of macro variable. |
|
f*****k 发帖数: 110 | 41 It seems the following link is only for prior's first observation.So any
reference for his/her second observation -- "If you want to use SYMGET to
input the value to the data set, then the
macro variable must be global"--? I just feel that it would be convenient if
SYMGET can also use local macro variable even though only under special
conditions. Thanks. |
|
b**********i 发帖数: 1059 | 42 杯具。原来还觉得我已经精通spss了,可发觉要真正把spss搞通,还得会spss macro。
可是又有点不甘心,好歹我也会sas macro是不。 spss/sas/splus换来换去,哪个好
用就用哪个,结果什么都不精。。。。。。。。。。 羡慕只用sas的。。。。。。 |
|
b*****r 发帖数: 359 | 43 我得到的错误:
ERROR: A character operand was found in the %EVAL function or %IF condition
where a numeric operand is required. The condition was: beta_new > 1
ERROR: The macro SAMPLES will stop executing.
问题: 在macro里面怎样把由
data _null_; set sys_risk (obs =1);
call symputx("beta", beta);
run;
得到的符号型变量(beta)转换成数值型数据?
PS:在表格sys_risk里面,beta本来就是数值型数据,精确到小数点后6位。 |
|
k*******a 发帖数: 772 | 44 data _null_; set sys_risk (obs =1);
call symputx("beta", beta);
run;
beta_new = &beta ; format beta_new best24.;
run后面的data step的语句必须得出现在data step里面,不能单独出现
%if beta_new > 1 里面的 beta_new 应该要是一个macro variable, 否者系统认为
是 beta_new这个字符和 1 比较。 需要把beta_new的存到一个macro里面再用 |
|
l****u 发帖数: 529 | 45 Did you run it on your computer?
this code works well on mine.
%let beta=4;
%macro p;
%if %eval(&beta)>1 %then %do;
%put β
%end;
%mend;
%p
in log:
4
you have already defined beta as macro variable in data null step.
%eval(&beta) transfer it to a numeric value. |
|
d*******o 发帖数: 493 | 46 --------------Macro-------------
regular expression --> PROC FCMP
--------------Macro------------- |
|
c*****1 发帖数: 131 | 47 what I want to do is:
data temp;
set big;
keep A B C D some_other_vars ...;
run;
%do_the_magic;
data &out;
set &data;
keep A B C D;
.....
run;
%mend;
%do_the_magic(data=big,out=small);
In my opinion, if your macro is given to others to use and you do not expect
time-costing I/O operations caused by huge datasets, simplicity and
readable is much important than the efficiency. 1) does not save much time on small/mid-sized datasets. Also, if the dateset is really huge,... 阅读全帖 |
|
h******s 发帖数: 3420 | 48 比如:
%let year=2000;
Macro 程序 of year 2000
如果想对2000- 2010 年都运行同样macro 程序, 我现在只会manually 把
%let year=2000; 改成%let year=2001, 2002........etc
请问有什么简洁的办法吗?
谢谢 |
|
k*******a 发帖数: 772 | 49 再写一个macro嵌套这个macro,用%do |
|
A*******s 发帖数: 3942 | 50 我一时半刻看不出来这个0怎么来
但是你是不能这么用macro的
macro不是函数,没有返回值,只是文本替换而已。 |
|