由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - help need for SAS macro
相关主题
SAS help : how to macro odsSAS应用问题
一个SAS Macro和Append的问题,救助!请教一个用SAS作DATA MERGE的问题
借人 气问 两个 问题:请教一下SAS编程的一个问题
用尽心思做好了一个macroSAS code help
请教如何写这个sas代码?求教 SAS base 123 Q 16
How to the macro regression with if?SAS Question 请教
今天又“R”了 -- 感想和请教。请问一个SAS proc sql的写法
请教一个SAS coding[合集] 一个sas问题
相关话题的讨论汇总
话题: data话题: num话题: sas话题: macro话题: data100
进入Statistics版参与讨论
1 (共1页)
s********l
发帖数: 245
1
I meet a problem during the work.
I have 100 data sets need to read into SAS, such as:
data1
1 2 3 4
data2
2 3 4 8
......
data100
2 4 8 9
I want to read these 100 data to SAS and merge that to one data set,what
kind of macro I should write? Many thanks.
s********l
发帖数: 245
2
The code I wrote is:
%macro data(num);
%do i=0 %to #
data est#
infile "path\data&num";
input a b c d;
run;
proc append base=data1 data=est#
run;
%mend;
%data(num=100);
through above program, I just got data combine with the data1 and the
data100. What's wrong with my program? I really need help from you! Many
thanks.
h***i
发帖数: 634
3
try force option in PROC APPEND
What warning did you get in log?

【在 s********l 的大作中提到】
: The code I wrote is:
: %macro data(num);
: %do i=0 %to #
: data est#
: infile "path\data&num";
: input a b c d;
: run;
: proc append base=data1 data=est#
: run;
: %mend;

s*r
发帖数: 2757
4
&i or &num

【在 s********l 的大作中提到】
: The code I wrote is:
: %macro data(num);
: %do i=0 %to #
: data est#
: infile "path\data&num";
: input a b c d;
: run;
: proc append base=data1 data=est#
: run;
: %mend;

s********l
发帖数: 245
5
what do you mean by &i and &num? Define both of as macro variables? Many
thanks.
x**m
发帖数: 941
6
I think your code failed to create the transit dataset, which is the
combination from data1 to data100 every loop.
BTW, where is the 'end;" ? Do I misunderstand sth here?
D******n
发帖数: 2836
7
stare at these two lines for at least 2 mins, and you will know.
o******6
发帖数: 538
8
%macro combined(total);
data a;
set %do i=1 %to &total; data&i %end;;
run;
%mend;
%combined(100)

【在 s********l 的大作中提到】
: I meet a problem during the work.
: I have 100 data sets need to read into SAS, such as:
: data1
: 1 2 3 4
: data2
: 2 3 4 8
: ......
: data100
: 2 4 8 9
: I want to read these 100 data to SAS and merge that to one data set,what

s********l
发帖数: 245
9
many thanks, but the data set is not SAS data, it is txt data, so I could
not use set to read it directly.
o****o
发帖数: 8077
10
if by 'merge' in your OP, you meant concatenation, then you can do similar
things like below:
data _null_;
file '/UNIX/oloolo/test1.txt';
x1=1; x2=2; x3=3; x4=4;
put x1 x2 x3 x4;
file '/UNIX/oloolo/test2.txt';
x1=11; x2=12; x3=13; x4=14;
put x1 x2 x3 x4;
run;
data new;
infile '/UNIX/oloolo/test1.txt';
input x1-x4; output;
infile '/UNIX/oloolo/test2.txt';
input x1-x4; output;
run;
use a macro to wrap all files
if it is merge then the case is a

【在 s********l 的大作中提到】
: many thanks, but the data set is not SAS data, it is txt data, so I could
: not use set to read it directly.

相关主题
How to the macro regression with if?SAS应用问题
今天又“R”了 -- 感想和请教。请教一个用SAS作DATA MERGE的问题
请教一个SAS coding请教一下SAS编程的一个问题
进入Statistics版参与讨论
o******6
发帖数: 538
11
%macro data(num);
%do i=1 %to #
data est&i;
infile "path\data&i";
input a b c d;
run;
proc append base=newdata data=est&i force;
run;
%end;
%mend;
%data(num=100);

【在 s********l 的大作中提到】
: The code I wrote is:
: %macro data(num);
: %do i=0 %to #
: data est#
: infile "path\data&num";
: input a b c d;
: run;
: proc append base=data1 data=est#
: run;
: %mend;

s********l
发帖数: 245
12
I used the above program, but the problem is that it just run once not 100
times.
s********l
发帖数: 245
13
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.
o******6
发帖数: 538
14
%macro new(num);
filename combine (%do i=1 %to #"path\data&i..txt" %end;);
data newdata;
infile combine;
input a b c d;
run;
%mend;
%new(100);

num

【在 s********l 的大作中提到】
: 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.

Y****a
发帖数: 243
15
在你的%do loop里没有&i什么事吗
把loop里所有的&num改成&i试试吧
这也是 sir 的意思
另外,为什么用append,不用set?

【在 s********l 的大作中提到】
: The code I wrote is:
: %macro data(num);
: %do i=0 %to #
: data est#
: infile "path\data&num";
: input a b c d;
: run;
: proc append base=data1 data=est#
: run;
: %mend;

1 (共1页)
进入Statistics版参与讨论
相关主题
[合集] 一个sas问题请教如何写这个sas代码?
Stupid SAS programming style is driving me crazy....How to the macro regression with if?
Need advice on SAS macro debugging今天又“R”了 -- 感想和请教。
如何添加时间变量请教一个SAS coding
SAS help : how to macro odsSAS应用问题
一个SAS Macro和Append的问题,救助!请教一个用SAS作DATA MERGE的问题
借人 气问 两个 问题:请教一下SAS编程的一个问题
用尽心思做好了一个macroSAS code help
相关话题的讨论汇总
话题: data话题: num话题: sas话题: macro话题: data100