h******e 发帖数: 1791 | 1 在一个macro里,如果call symput前面没有定义其他macro variable(包括macro的参
数),call symput定义的macro variable就是global的。这就是为什么call symputx
在某些条件下更好使的原因。 |
|
p***r 发帖数: 920 | 2 purpose: 想要做一个macro 循环调用 display, 输出不同的 survey answer as text,
然 后再根据其内容,人工的输入yes/no,以便于以后的数据分析。
problem: 整个 macro 可以运行,唯一的问题是,display 的 window 在循环调用的时
候不能正确的显示 survey answer. (我是将所有的 survey answer 输出到一连串
macro variable 里面去)。
Any solution or suggestion in proving the code is appreciated
code is here
################################
data surveydata;
input x $40.;
cards;
This is programe is useless
I dont think so
Maybe its usefull
Not very much
;run;
%macro survey;
data _null_;
set surveydat... 阅读全帖 |
|
l*****8 发帖数: 483 | 3 1. In a macro, if you use SYMPUT in data step, the macro variable you
created is NOT always global.
try the following 2 examples...
%macro prtrost(num=1);
data _null_;
call symput(’today’,trim(left(put(today(),mmddyy10.))));
run;
%mend prtrost;
%prtrost(num=8);
%put _all_; |
|
d******9 发帖数: 404 | 4 使用 call symput to create macro variables, the created macro variables can
NOT be referenced in the same data step, for example:
Data B;
Set A;
Call symput(X, Name);
Run;
We can only refer to use X in the following data step or Proc, but not in the same step.
However, what about Proc SQL INTO clause?
I run the below codes on SAS 9.1:
Proc sql;
select count(*) into: N
from aaa;
%let Y=&N;
%put ***************;
%put N=*&N*;
%put Y=*&Y*;
quit;
It turned out that both N and Y are resolved without an... 阅读全帖 |
|
A****t 发帖数: 141 | 5 把data step variable的值赋给macro variable,要用symput不能用%let,因为在data
step编译之前,macro语句就已经被执行了,所以你的%eval(x)里面,x就只是一个
character x
把%let那一行改成call symput('x',trim(left(x))); 应该就可以了 |
|
g****8 发帖数: 2828 | 6 %let是不行的。
光用call symput还不行,因为你得到的是最后一行的那个值,每一步都是。
要每次值不一样,得每一步跟着换变量名。
call symput('x'||put(_N_,best.),trim(left(x)));
这样,就涉及到调用的时候也需要跟着换的问题。
想了想,没有什么好方法,可能搞个自增的macro var &i在date step里面然后再用&&
x&i调用。
个人觉得SAS这个只取最后一行值,挺脑残的,下个版本应该改进一下。
data |
|
s*******2 发帖数: 499 | 7 可是SAS材料是这么写的;
You can create local macro variables with parameters in a macro definition
%LET statement within a macro definition
DATA step that contains a SYMPUT routine within a macro definition
SELECT statement that contains an INTO clause in PROC SQL within a
macro definition
%LOCAL statement.
是不是说marco内用call symput定义的是local marco variable呢? |
|
o******6 发帖数: 538 | 8 proc means data=a p50;
var xxx;
ods output summary=median;
run;
data a;
if _n_=1 then set median;
set a;
if xxx=. then xxxcat=.;
else if xxx le xxx_P50 then xxxcat=0;
else xxxcat=1;
run;
或者用 CALL SYMPUT:
data _null_;
set median;
call symput ('median',xxx_p50);
run;
............. |
|
s******r 发帖数: 1524 | 9 大包子 pls.
%macro test;
proc sql;
create table var_ls as select distinct name from dictionary.columns
where libname='WORK' and memname='TEST' and upcase(name) ne 'ID';quit;run;
data _null_;set var_ls;
call symput(cats('var',_n_),name);
call symput('cnt',_n_);
run;
proc sql;
create table test2 as
select id
%do i = 1 %to &cnt;
,max(&&var&i) as &&var&i
%end;
from test
group by id;quit;run;
%mend;
%test;
but |
|
j*****7 发帖数: 4348 | 10 libname test "X:\XXX\XXX\XXX";
proc sql noprint;
create table ddfdata as
select memname as dataset label='Data Set Name',
name as variable label='Variable Name',
label label='Variable Label',
type label='Variable Type',
count (distinct memname) into :totmem
from sashelp.vcolumn where libname='TEST'
order by dataset,name;
quit;
%macro trans;
data _null_;
set ddfdata;
by dataset notsorted;
retain b 1;
if first.dataset then do;
call symput(compress(trim(left('member'||t... 阅读全帖 |
|
s******3 发帖数: 57 | 11
谢谢大侠的指点, 能解释一下这道题考察的要点是什么吗? 为什么以下程序(仍用原始
数据库a) 仍然不能产生'low' value 哪? dataset a only contains 6 observations
so ELSE statement should be executed.....
%macro test;
data out;
set a nobs = totalobs;
%if totalobs > 10 %then %do;
call symput ('rc','high');
%end;
%else %do;
call symput ('rc','low');
%end;
run;
%mend;
%test
%put value of rc is &rc; |
|
s********e 发帖数: 255 | 12 Dear all,
I’m having a problem writing a SAS macro.
Briefly, I would like to store values of a variable from a dataset to a
macro variable, and use those values in the regression model.
For example, the B variable in the following model is a continuous model and
I would like to update the &I in the following model with a series of
values of B, such as 2, 6, 9, 13, etc, one for each time.
PROC RLOGIST DATA=FINAL FILETYPE=SAS;
NEST SDMVSTRA SDMVPSU;
WEIGHT WTDR2D4YR;
CLASS A;
MODEL Y= A... 阅读全帖 |
|
w*****3 发帖数: 1 | 13 下面是我写的macro,第一个step我想把temp数据里面的marital_status变量读到macro
变量里,然后第二个step用macro变量把所有的marital_status连接成一个字符串。
数据和程序是:
DATA Test;
FORMAT Marital_Status $10.;
INPUT ID Age Marital_Status $ @@;
CARDS;
1 24 Unknown 2 29 Single
3 24 Divorced 4 29 Divorced
5 30 Single 6 30 Separated
7 39 Unknown 8 35 Divorced
9 42 Separated 10 41 Separated
11 44 Separated 12 47 Unknown
13 45 Divorced 14 47 Married
15 48 Widow 16 49 Married
17 51 Single 18 54 Single
19 53 Divorced 20 55 Single
21 55 Married 22 56 Divorced
23... 阅读全帖 |
|
r******o 发帖数: 81 | 14 其实我就是想在一个data step中创建一个macro variable: testvar,但是还需要紧接
着就可以用这个macro variable来创建一个新变量:a2。
我知道call symput创建的macro var必须先把当前data step关闭才可以调用,请问还
有别的办法可以完成我的这个编程想法吗?
谢谢大家了!!
data test1;
input a b c;
cards;
1 1 1
;
run;
data test2;
set test1;
do i = 1 to 2;
a1 = i;
call symput('testvar',a1);
%put &testvar.;
a2 = &testvar.; *ALL I want is to get a2 = 1 for the first record and 2 for
the second record in a dynamic way;
output;
end;
run |
|
e*********5 发帖数: 151 | 15 我觉得你在data step加一行call symput("binwd", (max_age -min_age / 10));就好
了。 主意我用的symput不是symputn,我不了解后者
另外我不明白你为啥用symget,呼叫macro不是应该都用&么?比如&max_age,不管data
step还是sql.这个字符型数值型没关系吧 |
|
w******i 发帖数: 1476 | 16 SAS Interview Questions from http://www.sconsig.com/
Very Basic
What SAS statements would you code to read an external raw data file to a DATA
step?
How do you read in the variables that you need?
Are you familiar with special input delimiters? How are they used?
If reading a variable length file with fixed input, how would you prevent SAS
from reading the next record if the last variable didn't have a value?
What is the difference between an informat and a format? Name three informats
or format... 阅读全帖 |
|
p********a 发帖数: 5352 | 17 ☆─────────────────────────────────────☆
chrd (绵羊) 于 (Thu Feb 22 09:53:12 2007) 提到:
我有很多文件如下(相同结构):
A_00001.txt
A_00002.txt
.
.
A_09999.txt
我想用一个简单的macro去批处理文件,读入sas 合并成一个data set。如果是A_1.TXT
形式,我知道如何做,但现在是00001,就出问题了。
%MACRO FILE;
data A_&I;
%do i=00001 %to 09999;
infile "d:\A_&i..txt";
file_id=&i;
%END;
%MEND;
sas总是认为i=1,2 ....
谢谢
☆─────────────────────────────────────☆
papertigra (长工胖头猪) 于 (Thu Feb 22 12:58:17 2007) 提到:
options macrogen;
data _null_;
do i=1 to 9999;
call symput('a'||l |
|
EA 发帖数: 3965 | 18 I google some code and made some changes, but it didn't work, can anyone
help me out?
data _null_;
array test(*) _character_;
array allmiss (*) $ _temporary_ ('true');
length list $ 50;
set missing end=end;
do i=1 to dim(test);
if test(i) ne '' then allmiss(i)='false';
end;
if end=1 then
do i= 1 to dim(test);
if allmiss(i) ='true' then list=trim(list)||' '||trim(vname(test(i)));
end;
call symput('mlist',list);
run;
data notmiss;
set missing;
drop &mlist;
run; |
|
s*****e 发帖数: 9 | 19 %MACRO LOOP1 (INPUT);
%LOOP2;
%PUT DATE IS &DATE;
%MEND;
%MACRO LOOP2;
CALL SYMPUT('DATE', '28SEP1998');
%MEND;
%LET DATE=31DEC2006;
% LOOP1(&DATE)
What message is generated by %PUT?
A. DATE IS 31DEC2006 read from global symbol table.
B. DATE IS 28SEP1998 read from local symbol table of LOOP1
C. DATE IS 28SEP1998 read from local symbol table of LOOP2
D. DATE IS 28SEP1998 read from global symbol table.
应该是那个答案,为什么呢?谢谢 |
|
c*******o 发帖数: 8869 | 20 the major difference bw SAS and other programming language is that SAS has a
build-in loop for data reading. If you process SAS in the DATA step, SAS
automatically loop through all the data without the need to manually set up
an array and loop.
in your case, if you want to read the value of varname1 from observation 10
into a macro variable, you can do the followings:
data _null_;
set yourdata;
if _n_=10 then call symput('read',varname1);
run;
now the value of varname1(character) is re |
|
d*******1 发帖数: 854 | 21 you need to change your mindset when you switch from R, matlab to SAS, which
is a basically data language.
If your variable x is stored in a data set in which variable x has 100
observation. such as
data test;
do i=1 to 100;
x=rnorm(1); output;
end;
run;
One way to call them is to make every observation a macro variable as
follows:
data _null_;
set test;
call symput('x_'||trim(left(put(_n_,best.))),trim(left(put(x,best.))));
run;
Now, you can call any x by using macro |
|
a****e 发帖数: 5 | 22 The local symbol table of ONE is not empty (it contains parameter INPUT).
So, I think symput should 把新建的date写入 local table ONE. |
|
c*****r 发帖数: 2 | 23 Could anybody help me find out what's wrong with my codes?
The followings are my SAS codes:
options noxwait noxsync;
x "C:\progra~1\micros~1\Office\EXCEL.EXE"; /* opens Excel */
run; quit;
data _null_;
x=sleep(5); /*wait 3 seconds to give Excel time to open*/
run;
filename sexcel dde 'excel|system';
data _null_;
set table_name;
call symput('name'||left(_n_),filename);
run;
%macro open_file(file_name);
*%let path1=%quote(P:\IS\FOOTPR |
|
q**j 发帖数: 10612 | 24 call symput is invoked twice. |
|
s*********h 发帖数: 16 | 25 1。
At the start of a new SAS session; the following program is submitted:
%macro one;
data _null_;
call symput(’proc’,’means’);
run;
proc &proc data=sashelp.class;
run;
%mend;
%one()
What is the result?
(A) The marco variable PRCO is stored in the SAS catalog WORK.SASMACR
(B) The program fails to execute because PROC is a reserved word
(C) The macro variable PROC is stored in the local symbol table
(D) The macro variable PROC is stored in the global symbol table
2。
The following SAS program is s |
|
I**A 发帖数: 96 | 26 1. symput put the macro variable in the local symbol table only when local
symbol table exists;
2. be clear about excution time and compiling time. The 'if' statement can
not control the '%let' statement because they work in two different time
periods.
3. 'distinct' will sort the values. |
|
s*********h 发帖数: 16 | 27 还有些疑问:
1:how to create a local symbol table? why symput in a data within a macro
definition cannot create a local symbol table itself? |
|
o******6 发帖数: 538 | 28 ☆─────────────────────────────────────☆
acervulina (acervulina) 于 (Sat Jul 4 13:17:26 2009, 美东) 提到:
23.
Give the SAS data set one:
Group Sum
A 765
B 123
C 564
The following SAS program is submitted:
data_null_;
set one;
call symput(group, sum);
stop;
run;
what is the result when the program finishes execution?
A: Macro variable A has a value of 765;
B: Macro variable C has a value of 564;
C: Macro variable group has a value of 564,
D: Macro variable group has a value of sum.
Answer: A
I do |
|
s****l 发帖数: 129 | 29 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: There were 3 observations |
|
l***a 发帖数: 12410 | 30 38 %else %if %sysfunc(weekday(%sysfunc(today()))) in (4,6) %then %do;
39 data _null_; call symput('n',4); run;
40 %end;
ERROR: Required operator not found in expression: %sysfunc(weekday(%sysfunc(
today()))) in (4,6)
ERROR: The macro DATES will stop executing. |
|
q**j 发帖数: 10612 | 31 you are greedy, but greed is good :)
1. get unique group numbers into a table.
proc sort data = yourdata out=group(keep=group) nodupkey;
by group;
run;
2 do a lot of preparation.
data _NULL_;
set group end=lastobs;
name = cats("group",group);
call symput(cats("group",_n_),name);
if _n_ = 1 then
do;
longname= name;
longgroupvalue= '"'||cats(group)||'"';
end;
else
do;
longname=cats(longname)|| " "||cats(name);
longgroupvalue = cats(longgroupvalue)||", "||'"'||cats(group)||'"';
end;
if lastobs then |
|
D******n 发帖数: 2836 | 32 data _null_;
set a1;if (id=2) then call symput('value',var2);run;
data a2;
set a1;if (id=1) then var1 = &value;run; |
|
D******n 发帖数: 2836 | 33 how about this?
%let sites =site1 site3 site6;
data _null_;
siteno = substr(tranwrd("&sites","site",","),2);
call symput("siteno",siteno);run;
and |
|
q**j 发帖数: 10612 | 34 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. |
|
q**j 发帖数: 10612 | 35 i agree. but i tend to think using 'call execute' let people write shorter,
but harder to read, codes than 'call symput plus macro loop'. do not you
feel a little confused when staring at a block of call execute? |
|
c****g 发帖数: 156 | 36 DATA _NULL_;
call symput ('today', compbl(put(today(), date9.)));
run;
proc export data = files
outfile = "c:\filename&today." dbms = xls replace ;
run; |
|
|
A*******s 发帖数: 3942 | 38 非牛人解释一下
%let statement is processed by the macro processor before data step is
executed.
macro processor first scans "%let rc = high" and assigns "high" to rc; Then
scans "%let rc = low" and assigns "low" to rc. No matter what data step does
later on, rc's value is fixed.
To change the value in a macro variable in data step, you need to use call
symput. |
|
R******d 发帖数: 1436 | 39 这个宏凑合看看吧
%macro pgxofy(filein=,flag=(Page x of y),append=N,outfile=,ls=132)/des='Page
x of y';
*以&flag为标识算总页数;
data _null_;
retain pg 0;
infile "&filein" end=last;
input;
if index(upcase(_infile_),"&flag") then do;
pg=pg+1;
end;
if last then call symput("totpg",put(pg,4.0));
run;
*将&flag标识替换为“page X of Y”;
data tttttttt;*(keep=text);
length text2 text $200.;
retain pg 0;
infile "&filein";
input;
if index(upcase(_infile_),"&flag") the |
|
b**********e 发帖数: 531 | 40 data _NULL_;
if 0 then do;
set _temp_ nobs=nobs1;
end;
call symput ('num1', nobs1);
stop;
run;
_temp_ is a cecent dataset sas create, the "nobs" is the total number of
obs in the data ? |
|
A*******s 发帖数: 3942 | 41 i don't understand most of questions you asked.
For this one, "how can I get a macro variable with the value of the number
of records in A"
two ways:
data _null_;
set A nobs=nobs;
call symput('Ur_Macro', nobs);
run;
proc sql;
select distinct * into: Ur_macro
from A;
run;
values
the |
|
A*******s 发帖数: 3942 | 42 my 2 cents, correct me if i were wrong:
1. transpose X dataset. Then you have two rows and 10 columns. You can use
functions in data-step, which I think is more efficient than proc sql
functions.
2. Then use call symput routine to pass the value of Likelihood(lambda) to
macro variable for each row.
3. Iterate the calculation with a %do loop, like this(there may be some
syntax errors):
%do lambda=-5 %to 5 %by 0.05;
%let i=1;
data transposed;
set transposed;
likelihood=(your function);
call sy |
|
|
|
|
f*******e 发帖数: 51 | 46 data _null_;
set yourfile end=eof;
array char _character_ ;
do over char;
if char =" " then inx+1;
end;
if eof then call symput("total", left(inx));
%put &total;
run;
not sure if it's what u need or not |
|
h**********e 发帖数: 44 | 47 First create a dataset:
data index;
input i;
datalines;
1
3
6
7
run;
Then
%do j=1 &to 4;
data a;
set index (obs=&j);
call symput('i',i);
run;
/*do whatever you want to do with &i here*/
...
%end;
This is what I usually do this kind of work. Remember macro in SAS is not as
easy as function in C. SAS is dataset oriented in most of the cases. |
|
u******e 发帖数: 60 | 48 Please try this one.
data a2;
set a1 ;
idnew =id4;
run;
%macro setID(idvar);
%let complete=no;
%let idnewFrom=;
%let idnewTo=;
%do %while (&complete=no);
proc sort data=a2; by &idvar idnew;
data a2(drop=idT change);
set a2 end=last;
by &idvar idnew;
retain idT change;
Preidnew =idnew;
if _N_=1 then change=0;
if first.&idvar and change=0 then idT =idnew;
else do;
if change=0 and idT ^= idnew then do;
call symput("idnewFrom", left(idnew)); |
|
P******V 发帖数: 83 | 49 还有三道130题里的问题:
81 At the start of a new SAS session, the following program is submitted:
%macro one;
data _null_;
call symput('proc','means');
run;
proc &proc data=sashelp.class;
run;
%mend;
%one()
what is the result?
A the macro variable proc is stored in the local symbol table.
B the macro variable proc is stored in the global symbol table.
C the macro variable proc is stored in the SAS catalog WORK.SASMACR
D the program fails to execute because PROC is a reserved word
这倒题答案是B,不过我不明白为什么proc是GLO |
|
a********s 发帖数: 188 | 50 提示点思路吧。。。
(1)可以先用proc contents输出每个variable name
(2)用 call symput 建立一组macro variables, ex: var1, var2,...
(3) 在proc sql中用DO Loop 算 nmiss(&&var&i)...
这样应该可以实现。 我以前写过一个简单的算每个变量的missing proportion的macro
。找不到在哪里了。。。 相信proc means也很好实现。 |
|