SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 1024|回复: 4
打印 上一主题 下一主题

请教SAS的问题

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2007-1-30 05:32:06 | 只看该作者

请教SAS的问题

希望各位SAS 的牛人,帮忙解决下列SAS的问题。万分感谢!!!

1.

a) There is a large file with an ID-Key field and a TYPE field.  Both fields are characters.  Also, there are extra fields in addition to those two.  The extra fields are all numeric.  The content of the TYPE field is such that each record contains the name of one and only one of those extra numeric fields.  

You are asked to do the following:
For each record, only output the ID-Key, TYPE and the numeric field that bears the name of the content of the TYPE record, such that different numeric fields are output to different file.

b) Suppose that the code in part a) is to be re-used. You are not given the number of numeric fields in this file.  Write code to find out the number of numeric fields.



2. Refer to the output files in (1.a). Provide code so that the names of the numeric field in each file are VAR1, VAR2, …etc.  The order should be the same as if you sort the TYPE field in ascending order.




3.Refer to the output files in (1.a). You are asked to change all the names of the numeric fields so that they all have the same name.  Then append these files into one file so that the order of appending preserves the sorting of the TYPE field by ascending.




4.A large file FILE1 with half a million records has 3 fields, one of them is numeric, and the other two are character.  These two character fields index the file so that any pair of values of the character fields occurs at most once. There is another super file BIGFILE with hundreds of million records.  This super file has the same two character fields as FILE1.  Merge these two files so that only common elements of these two fields are extracted.  

Bear in mind that sorting a file with hundreds of million records requires a huge amount of time and that it is advisable not to sort it if not necessary.
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
沙发
 楼主| 发表于 2007-1-31 22:56:01 | 只看该作者

RE:

if you can post a sample of your dataset, that will be helpful to understand your question.
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
板凳
 楼主| 发表于 2007-2-1 22:58:58 | 只看该作者

re

1和2用macro和proc sql。方法几乎一样。
3用proc  append或者proc sql,再加宏。
4没有机会接触这么大的文件,proc sql似乎可以,但不知道这么大的文件行不行,也不知性能如何;或许data step的hash速度更快,对第二个文件建立hash,然后data step处理第一个文件。
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
地板
 楼主| 发表于 2007-2-1 23:50:44 | 只看该作者

第一个

其中q为原数据集,再稍微改一下第二题就可以了。第三题比较简单。
proc sql noprint;;
        select n(type) into:number from q;run;
proc sql noprint;
        select type into:x1-:x%cmpres(&number)
                        from q;
quit;

%macro try;
        %do m_i=1 %to &number;
        %put &&x&m_i;
                proc sql noprint;
                        create table &&x&m_i
                                as select &&x&m_i from q;
                quit;
        %end;
%mend;

%try

验证通过。
明天试试第四题。
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
5#
 楼主| 发表于 2007-2-1 23:52:34 | 只看该作者

re

好奇怪,出来了个人头,那是 : x
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2025-6-11 10:52 , Processed in 0.107098 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表