由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - 求助:一个SAS的小问题
相关主题
发包子求大牛解SAS问题,急SAS Dataset有什么最简单的办法能知道里面的最大值
SAS菜鸟请教如果使SAS的output的结果放到一个文件内?Please help with a SAS macro
问一个SAS macro的问题A SAS Data Question
请问关于交易量的一个SAS编程问题请教SAS ODS to Excel
SAS Technical Interview QuestionsSAS Code 求助,如何把在另一个dataset的id找出来
SAS base questionSAS Macro求教
请教一个SAS文件循环生成的小问题[合集] 请教一个sas问题
SAS code求教怎么快速将 大的暂时sas data 存为永久sas data?
相关话题的讨论汇总
话题: firms话题: sas话题: input话题: mydata话题: macro
进入Statistics版参与讨论
1 (共1页)
D*o
发帖数: 210
1
先多谢大家。
我有一个文件,其中一个variable name是:Firms,
Firms的值可以是F1, F2,F3,.........Fn;
我现在想要让sas自动create n个文件,并且指定文件名就是Firms 这个变量的value,
然后每个observation根据他们Firms这个变量的值分配到相应的文件里。麻烦指点一下
具体应该怎么做,或者应该用什么命令。
d******9
发帖数: 404
2
Use macro.
sas自动create n个文件, 什么文件??? If SAS datasets, easy. If other
application files, maybe need use X statement.
s*******e
发帖数: 1385
3
%macro test;
proc sql;
select distinct firms into: firmvars separated by ' '
from yourdata;
quit;
%do i=1 %to %sysfunc(countw(&firmvars));
%let firmvar=%scan(&firmvars., &i., ' ');
data &firmvar.;
set yourdata;
where Firms="&firmvar.";
run;
%end;
%mend test;
%test

【在 D*o 的大作中提到】
: 先多谢大家。
: 我有一个文件,其中一个variable name是:Firms,
: Firms的值可以是F1, F2,F3,.........Fn;
: 我现在想要让sas自动create n个文件,并且指定文件名就是Firms 这个变量的value,
: 然后每个observation根据他们Firms这个变量的值分配到相应的文件里。麻烦指点一下
: 具体应该怎么做,或者应该用什么命令。

D*o
发帖数: 210
4
没有说清楚,就是datasets 谢谢

【在 d******9 的大作中提到】
: Use macro.
: sas自动create n个文件, 什么文件??? If SAS datasets, easy. If other
: application files, maybe need use X statement.

d******9
发帖数: 404
5
This macro works, but it is not a good macro.
如果楼主需要的不是 SAS datasets 呢?

【在 s*******e 的大作中提到】
: %macro test;
: proc sql;
: select distinct firms into: firmvars separated by ' '
: from yourdata;
: quit;
: %do i=1 %to %sysfunc(countw(&firmvars));
: %let firmvar=%scan(&firmvars., &i., ' ');
: data &firmvar.;
: set yourdata;
: where Firms="&firmvar.";

d******9
发帖数: 404
6
Then it is very easy
%macro AAA;
proc sql;
select conunt(distinct Firms) into : N
from Input_Table;
%let N=&N;
select distinct strip(Firms) into : F_1 - : F_&N
from Input_Table;
quit;
%local I;
%do I=1 %to &N;
data &&F_&I;
set Input_Table;
where Firms="&&F_&I";
run;
%end;
%mend;

【在 D*o 的大作中提到】
: 没有说清楚,就是datasets 谢谢
D*o
发帖数: 210
7
多谢 我试试看。

【在 d******9 的大作中提到】
: Then it is very easy
: %macro AAA;
: proc sql;
: select conunt(distinct Firms) into : N
: from Input_Table;
: %let N=&N;
: select distinct strip(Firms) into : F_1 - : F_&N
: from Input_Table;
: quit;
: %local I;

k*******a
发帖数: 772
8
there are many ways to do this, here is my solution:
data MyData;
input firm $ x;
datalines;
F1 1
F2 3
F3 5
F3 6
F1 9
F2 99
F6 3
;
run;
proc sql noprint;
select distinct firm into :data separated by ' ' from MyData;
select distinct "if firm ='"||strip(firm)||"' then output "|| firm into
:code separated by '; ' from MyData;
quit;
data &data;
set MyData;
&code;
run;
d******9
发帖数: 404
9
Yes, this is another way, without using macro do-loop.
But, if the input data set is huge and the variable Firms has thousands of
levels, then this method is not efficient, esp. when you use a lot IF... IF
rather than IF-ELSE IF.

【在 k*******a 的大作中提到】
: there are many ways to do this, here is my solution:
: data MyData;
: input firm $ x;
: datalines;
: F1 1
: F2 3
: F3 5
: F3 6
: F1 9
: F2 99

k*******a
发帖数: 772
10
这个改下code不难
改成 separated by ';else ' 就可以了

IF

【在 d******9 的大作中提到】
: Yes, this is another way, without using macro do-loop.
: But, if the input data set is huge and the variable Firms has thousands of
: levels, then this method is not efficient, esp. when you use a lot IF... IF
: rather than IF-ELSE IF.

D*o
发帖数: 210
11
多谢

IF

【在 d******9 的大作中提到】
: Yes, this is another way, without using macro do-loop.
: But, if the input data set is huge and the variable Firms has thousands of
: levels, then this method is not efficient, esp. when you use a lot IF... IF
: rather than IF-ELSE IF.

1 (共1页)
进入Statistics版参与讨论
相关主题
怎么快速将 大的暂时sas data 存为永久sas data?SAS Technical Interview Questions
请教data mining 的问题,在线等,谢谢!SAS base question
菜鸟问个sas得问题,关于分数组请教一个SAS文件循环生成的小问题
请教一个问题,谢谢。SAS code求教
发包子求大牛解SAS问题,急SAS Dataset有什么最简单的办法能知道里面的最大值
SAS菜鸟请教如果使SAS的output的结果放到一个文件内?Please help with a SAS macro
问一个SAS macro的问题A SAS Data Question
请问关于交易量的一个SAS编程问题请教SAS ODS to Excel
相关话题的讨论汇总
话题: firms话题: sas话题: input话题: mydata话题: macro