由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - 请教一个SAS 数据分配问题
相关主题
请教一个SAS Macro的问题Weird SAS macro bugs, 包子重谢!
SAS help : how to macro odssas 代码问题
SAS macro question【包子】求问个简单sas macro问题
[Help] Dividing a SAS data setNeed advice on SAS macro debugging
SAS sampling的问题一个常见的问题
Help for beginner of Macro请教一道SAS MACRO编程的问题。怎么都不明白。谢谢
Stupid SAS programming style is driving me crazy....请教SAS IML调用DATA step数据的问题
sas macro 问题如何添加时间变量
相关话题的讨论汇总
话题: 100话题: do话题: end话题: data话题: eval
进入Statistics版参与讨论
1 (共1页)
m********a
发帖数: 194
1
一个数据文件, 里面10000个observations,
想要把它分成100个小文件,每个里面含100个observations,
observation 1 to 100 go to data1.txt
observation 101 to 200 go to data2.txt
...
observation 9901 to 10000 go to data100.txt
也就是顺序把每100个obs放到一个新的.txt (or .dat) file 里面
请教一下,想写一个macro or something else?
多谢
t**i
发帖数: 688
2
In Data Step, use Do Loop and the step size is 100.
m********a
发帖数: 194
3
谢谢
试了一下,就是分配到不同文件的时候不知道怎么搞,因为这100个小文件要起不同的
名字, data1.dat 一直到 data100.dat
y****n
发帖数: 46
4
data temp;
do i=1 to 10000;
id=i;
xx=i/i**2;
output;
end;
drop i ;
run;
%macro out;
data %do x=1 %to 100; data&x %end;;
set temp ;
%do j=1 %to 99;
%if &j=1 %then %do;
if 1<=_n_<=100 then output data1;
%end;
%let k=%eval(&j+1);
if %eval(&j*100+1)<=_n_<=(%eval(&j+1)*100) then output data&k;
%end;
run;
%mend out;
%out
m********a
发帖数: 194
5
谢谢楼上啊!
好像只是生成了100个SAS系统数据, 还是没解决如何创建data1.dat, data2.dat....
data100.dat的问题。。。
D******n
发帖数: 2836
6
this question was raised before and i answered a quick way , but must be und
er linux system

【在 m********a 的大作中提到】
: 谢谢楼上啊!
: 好像只是生成了100个SAS系统数据, 还是没解决如何创建data1.dat, data2.dat....
: data100.dat的问题。。。

m********a
发帖数: 194
7
谢谢指点!
不懂Linux。。。头痛。。。
D******n
发帖数: 2836
8
非要在sas里面搞,搞个macro输出就行了

【在 m********a 的大作中提到】
: 谢谢指点!
: 不懂Linux。。。头痛。。。

o****o
发帖数: 8077
9
you can use hash table to do this:
data have; do i=1 to 1E6; output; end; run;
%macro hashinit;
h = _new_ hash ();
h.defineKey('id');
h.defineData('i');
h.defineDone();
%mend;
data _null_;
declare hash h;
%hashinit;
id=1;
do until (eof);
set have end=eof;
rc=h.add(); id+1;
_numitems=h.num_items;
if h.num_items=100 or eof then do;
if ^eof then _n=int(_numitems/100);
D******n
发帖数: 2836
10
天啊,SAS现在啥都有了。。。更烂了。

【在 o****o 的大作中提到】
: you can use hash table to do this:
: data have; do i=1 to 1E6; output; end; run;
: %macro hashinit;
: h = _new_ hash ();
: h.defineKey('id');
: h.defineData('i');
: h.defineDone();
: %mend;
: data _null_;
: declare hash h;

相关主题
Help for beginner of MacroWeird SAS macro bugs, 包子重谢!
Stupid SAS programming style is driving me crazy....sas 代码问题
sas macro 问题【包子】求问个简单sas macro问题
进入Statistics版参与讨论
m********a
发帖数: 194
11
太感谢了!
m********a
发帖数: 194
12
不好意思,试了一下好像不work。
请问
1.“have”是我自己原来的大的数据,是吗
2. “1E6”指代的是什么?
3. SAS log 不停滚动“work.data 1 has 500 obs and 1 variable”?
thanks a lot!

【在 o****o 的大作中提到】
: you can use hash table to do this:
: data have; do i=1 to 1E6; output; end; run;
: %macro hashinit;
: h = _new_ hash ();
: h.defineKey('id');
: h.defineData('i');
: h.defineDone();
: %mend;
: data _null_;
: declare hash h;

o****o
发帖数: 8077
13
1. yes
2. just to generate a big file having 100000 obs
3. there was a typo in my code. replace "_n=int(_numitems/100);" with "_n=
int(id/100);"

【在 m********a 的大作中提到】
: 不好意思,试了一下好像不work。
: 请问
: 1.“have”是我自己原来的大的数据,是吗
: 2. “1E6”指代的是什么?
: 3. SAS log 不停滚动“work.data 1 has 500 obs and 1 variable”?
: thanks a lot!

s*r
发帖数: 2757
14
data _null_

【在 m********a 的大作中提到】
: 谢谢楼上啊!
: 好像只是生成了100个SAS系统数据, 还是没解决如何创建data1.dat, data2.dat....
: data100.dat的问题。。。

m********a
发帖数: 194
15
改了之后,SAS log 不停滚动
“work.data 1 has 500 obs and 1 variable”
“work.data 2 has 500 obs and 1 variable”
.
.
.
“work.data 5000 has 500 obs and 1 variable”
... 还在滚动, 不知道到什么时候停止。。。
anyway, 非常感谢!

【在 o****o 的大作中提到】
: 1. yes
: 2. just to generate a big file having 100000 obs
: 3. there was a typo in my code. replace "_n=int(_numitems/100);" with "_n=
: int(id/100);"

o****o
发帖数: 8077
16
add options nonotes
your data is big and many small files are generated....so....

【在 m********a 的大作中提到】
: 改了之后,SAS log 不停滚动
: “work.data 1 has 500 obs and 1 variable”
: “work.data 2 has 500 obs and 1 variable”
: .
: .
: .
: “work.data 5000 has 500 obs and 1 variable”
: ... 还在滚动, 不知道到什么时候停止。。。
: anyway, 非常感谢!

m********a
发帖数: 194
17
thanks
又run了一下, 没提示出错,也没有任何结果。。。
s********9
发帖数: 74
18
I get the right result in WINDOWS system.
Thanks!

【在 y****n 的大作中提到】
: data temp;
: do i=1 to 10000;
: id=i;
: xx=i/i**2;
: output;
: end;
: drop i ;
: run;
: %macro out;
: data %do x=1 %to 100; data&x %end;;

D******n
发帖数: 2836
19
其实用sas做这个真是很费劲。用linux吧
split yourbigfile -l 100 smallfile -d
m********a
发帖数: 194
20
楼上试完了请来报告一下啊, 谢谢了
相关主题
Need advice on SAS macro debugging请教SAS IML调用DATA step数据的问题
一个常见的问题如何添加时间变量
请教一道SAS MACRO编程的问题。怎么都不明白。谢谢请教一个SAS Macro问题。谢谢
进入Statistics版参与讨论
o****o
发帖数: 8077
21
没有任何结果in your log, but check out the work library
data have; do i=1 to 1E6; output; end; run;
%macro hashinit;
h = _new_ hash ();
h.defineKey('id');
h.defineData('i');
h.defineDone();
%mend;
options nonotes nosource;
data _null_;
declare hash h;
%hashinit;
id=1;
do until (eof);
set have end=eof;
rc=h.add(); id+1;
_numitems=h.num_items;
if h.num_items=100 or eof then do;
if ^eo

【在 m********a 的大作中提到】
: thanks
: 又run了一下, 没提示出错,也没有任何结果。。。

l******r
发帖数: 12
22
Try this one, I bet it work:)
data have;
do i=1 to 10000;
val=ranuni(6);
output;
end;
run;
%macro try;
%do k=1 %to 100;
data dt_&k.;
set have;
if %eval((&k.*100)-99)=<_n_<=%eval(&k.*100);
run;
%end;
%mend try;
%try;
m********a
发帖数: 194
23
感谢回复!
log没显示错误, 但还是没有生成dataset1.dat, dataset2.dat, ...dataset100.dat
昨天在看你给的code时候不知道改了那个参数,后来发现log里有生成实体数据的记录
(dataset1.dat),但是因为错误而停止了,所以在文件夹里并没有看到含observation
的dataset1.dat.

【在 o****o 的大作中提到】
: 没有任何结果in your log, but check out the work library
: data have; do i=1 to 1E6; output; end; run;
: %macro hashinit;
: h = _new_ hash ();
: h.defineKey('id');
: h.defineData('i');
: h.defineDone();
: %mend;
: options nonotes nosource;
: data _null_;

m********a
发帖数: 194
24
感谢指点! yes, it works! 但是没有output 成实体数据dataset1.dat, dataset2.
dat, ...dataset100.dat。
不过还是谢谢了!

【在 l******r 的大作中提到】
: Try this one, I bet it work:)
: data have;
: do i=1 to 10000;
: val=ranuni(6);
: output;
: end;
: run;
: %macro try;
: %do k=1 %to 100;
: data dt_&k.;

g********d
发帖数: 2022
25
服了,这么简单的问题看折腾的。
%macro split;
%do i=1 %to 10000 %by 100;
data dataset&i ; set one (firstobs=&i obs=%eval(99+&i));run;
run;
%end;
%mend;
%split;
D******n
发帖数: 2836
26
u guys don't get it, lz wanted it diced into text files...not sas format fil
es...

【在 g********d 的大作中提到】
: 服了,这么简单的问题看折腾的。
: %macro split;
: %do i=1 %to 10000 %by 100;
: data dataset&i ; set one (firstobs=&i obs=%eval(99+&i));run;
: run;
: %end;
: %mend;
: %split;

g********d
发帖数: 2022
27
主贴没讲。
需要text的,加一行put语句,一样简单。

fil

【在 D******n 的大作中提到】
: u guys don't get it, lz wanted it diced into text files...not sas format fil
: es...

m********a
发帖数: 194
28
不好意思,是我没讲清楚。
谢谢点出了

fil

【在 D******n 的大作中提到】
: u guys don't get it, lz wanted it diced into text files...not sas format fil
: es...

o****o
发帖数: 8077
29
it works perfectly on my machine

dat
observation

【在 m********a 的大作中提到】
: 感谢回复!
: log没显示错误, 但还是没有生成dataset1.dat, dataset2.dat, ...dataset100.dat
: 昨天在看你给的code时候不知道改了那个参数,后来发现log里有生成实体数据的记录
: (dataset1.dat),但是因为错误而停止了,所以在文件夹里并没有看到含observation
: 的dataset1.dat.

m********a
发帖数: 194
30
在首页改了一下问题的描述
谢谢各位热心回复
相关主题
请教一个SAS ADV 的题目SAS help : how to macro ods
请帮忙看3道SAS题。SAS macro question
请教一个SAS Macro的问题[Help] Dividing a SAS data set
进入Statistics版参与讨论
m********a
发帖数: 194
31
谢谢
我再看看

【在 o****o 的大作中提到】
: it works perfectly on my machine
:
: dat
: observation

s*r
发帖数: 2757
32
i said data _null_. no one pays attention

fil

【在 D******n 的大作中提到】
: u guys don't get it, lz wanted it diced into text files...not sas format fil
: es...

D******n
发帖数: 2836
33
%macro split;
%do i=1 %to 10000 %by 100;
data _null_ ; set one (firstobs=&i obs=%eval(99+&i)); file 'smallfile'&i; pu
t (_all_) (+0);run;
run;
%end;
%mend;
%split;

【在 g********d 的大作中提到】
: 服了,这么简单的问题看折腾的。
: %macro split;
: %do i=1 %to 10000 %by 100;
: data dataset&i ; set one (firstobs=&i obs=%eval(99+&i));run;
: run;
: %end;
: %mend;
: %split;

o****o
发帖数: 8077
34
no need for macro, use array

pu

【在 D******n 的大作中提到】
: %macro split;
: %do i=1 %to 10000 %by 100;
: data _null_ ; set one (firstobs=&i obs=%eval(99+&i)); file 'smallfile'&i; pu
: t (_all_) (+0);run;
: run;
: %end;
: %mend;
: %split;

o******6
发帖数: 538
35
change file 'smallfile'&i to file "...\data%eval((&i-1)/100+1)";

pu

【在 D******n 的大作中提到】
: %macro split;
: %do i=1 %to 10000 %by 100;
: data _null_ ; set one (firstobs=&i obs=%eval(99+&i)); file 'smallfile'&i; pu
: t (_all_) (+0);run;
: run;
: %end;
: %mend;
: %split;

l******r
发帖数: 12
36
Ok OK, try this one. I am making the testing data smaller. you can change it
accordingly...
data have;
do i=1 to 100;
val=ranuni(6);
output;
end;
run;
%macro try;
%do k=1 %to 10;
data dt_&k.;
set have;
if %eval((&k.*10)-9)=<_n_<=%eval(&k.*10);
run;
DATA _NULL_;
FILE "C:\Temp\dt_&k..txt";
SET dt_&k.;
put i val;
RUN;
%end;
%mend try;
%try;
o******6
发帖数: 538
37
人家没那么笨吧,那个谁说了MAKE A SMALLER DATASET了啊,融会贯通总会吧
o******6
发帖数: 538
38
要有耐心啊,就好比学统计主要靠的是耐心
c*********n
发帖数: 87
39
大家都好可爱啊! 认真学习中。
o******6
发帖数: 538
40
是学习可爱?

【在 c*********n 的大作中提到】
: 大家都好可爱啊! 认真学习中。
相关主题
[Help] Dividing a SAS data setStupid SAS programming style is driving me crazy....
SAS sampling的问题sas macro 问题
Help for beginner of MacroWeird SAS macro bugs, 包子重谢!
进入Statistics版参与讨论
c*********n
发帖数: 87
41
解答问题的耐心人些,呵呵呵呵!正在调程序中.....

【在 o******6 的大作中提到】
: 是学习可爱?
c*********n
发帖数: 87
42
我试了一下,估计后面要加个后缀,比如.TXT,才能读!恩,谢谢了。刚才只用了一个
单引号,结果出不来,仔细一想,在macro里好像是双引号才对。谢谢各位集思广益啊
:)。

【在 o******6 的大作中提到】
: change file 'smallfile'&i to file "...\data%eval((&i-1)/100+1)";
:
: pu

o******6
发帖数: 538
43
m********a
发帖数: 194
44
thanks a lot!
这次可以了。

it

【在 l******r 的大作中提到】
: Ok OK, try this one. I am making the testing data smaller. you can change it
: accordingly...
: data have;
: do i=1 to 100;
: val=ranuni(6);
: output;
: end;
: run;
: %macro try;
: %do k=1 %to 10;

m********a
发帖数: 194
45
非常感谢回答问题的各位!
抱歉开始没说清楚,耽误你们时间,呵呵
o******6
发帖数: 538
46
这个最简单有效了啊
%macro split;
%do i=1 %to 10000 %by 100;
data _null_ ;
set temp (firstobs=&i obs=%eval(99+&i));
file "...\data%eval((&i-1)/100+1).txt";
put (_all_) (+0);
run;
%end;
%mend;
%split;

then datastep subsetting using where statement is the most efficient one?
load 10000 observation once, 100 observation 100 times.
D******n
发帖数: 2836
47
我的linux command最有效。=)

【在 o******6 的大作中提到】
: 这个最简单有效了啊
: %macro split;
: %do i=1 %to 10000 %by 100;
: data _null_ ;
: set temp (firstobs=&i obs=%eval(99+&i));
: file "...\data%eval((&i-1)/100+1).txt";
: put (_all_) (+0);
: run;
: %end;
: %mend;

o******6
发帖数: 538
48
不会:-(

【在 D******n 的大作中提到】
: 我的linux command最有效。=)
m********a
发帖数: 194
49
学习了
再次谢谢大家指点!
o****o
发帖数: 8077
50
windows(DOS)下有类似的命令么?特别是新的script出来以后?从没试过

【在 D******n 的大作中提到】
: 我的linux command最有效。=)
相关主题
sas 代码问题一个常见的问题
【包子】求问个简单sas macro问题请教一道SAS MACRO编程的问题。怎么都不明白。谢谢
Need advice on SAS macro debugging请教SAS IML调用DATA step数据的问题
进入Statistics版参与讨论
D******n
发帖数: 2836
51
windows 下面装个cygwin一样可以。

【在 o****o 的大作中提到】
: windows(DOS)下有类似的命令么?特别是新的script出来以后?从没试过
y****n
发帖数: 46
52
data temp;
do i=1 to 10000;
id=i;
xx=i/i**2;
output;
end;
drop i ;
run;
filename out "e:\temp";
%macro out;
data _null_;
set temp ;
%do j=1 %to 99;
%if &j=1 %then %do;
if 1<=_n_<=100 then do;
file out(data1.txt);
put id xx;
end;
%end;
%let k=%eval(&j+1);
if %eval(&j*100+1)<=_n_<=(%eval(&j+1)*100) then do;
file out(data&k..txt);
put id xx;
end;
%end;
run;
%mend out;
%out
y****n
发帖数: 46
53
data temp;
do i=1 to 10000;
id=i;
xx=i/i**2;
output;
end;
drop i ;
run;
filename out "e:\temp";
%macro out;
data _null_;
set temp ;
%do j=1 %to 99;
%if &j=1 %then %do;
if 1<=_n_<=100 then do;
file out(data1.txt);
put id xx;
end;
%end;
%let k=%eval(&j+1);
if %eval(&j*100+1)<=_n_<=(%eval(&j+1)*100) then do;
file out(data&k..txt);
put id xx;
end;
%end;
run;
%mend out;
%out
m********a
发帖数: 194
54
谢谢楼上的指点!
1 (共1页)
进入Statistics版参与讨论
相关主题
如何添加时间变量SAS sampling的问题
请教一个SAS Macro问题。谢谢Help for beginner of Macro
请教一个SAS ADV 的题目Stupid SAS programming style is driving me crazy....
请帮忙看3道SAS题。sas macro 问题
请教一个SAS Macro的问题Weird SAS macro bugs, 包子重谢!
SAS help : how to macro odssas 代码问题
SAS macro question【包子】求问个简单sas macro问题
[Help] Dividing a SAS data setNeed advice on SAS macro debugging
相关话题的讨论汇总
话题: 100话题: do话题: end话题: data话题: eval