Jiangtang's profile技止于此BlogListsNetwork Tools Help

Blog


    1/21/2008

    用SAS读入原始数据(1):文本文件(续)

    *****************************************************

    用SAS读入原始数据(1):文本文件

    ****************************************************

    总结一下,有两种文本文件,及其对应的读入方法:

    1. 字段固定(Fixed Filed)——列输入模式(Column)、格式化输入模式(Formatted)
    2. 分隔符固定(Delimited Data)——列举输入模式(List)

    字段固定的文本文件,列输入模式

    1. 对数值变量,只能读入标准数据,包括正负号、小数点、数字、和由E构成的科学计数;
    2. 不能够读入日期时间,以及包含美元符号、逗号等字符的数值;
    3. 对字段的选择非常灵活,可以任意选择字段和读入的次序。

    格式化输入模式

    1. 由指针控制读入的列数;
    2. 可以设定输入格式。

    分隔符固定的文本文件,列举输入模式

    对分隔符固定的文本文件,系统根据分隔符就能区分各个变量,对系统默认的以空格为分隔符的数据文件,列举输入模式的input语句最为简单:

    input 变量名<s>;

    以下是一些扩展:

    1. 如果源文件不是以空格为分隔符,比如是用逗号做分隔符,那么需要在infile语句后面加上 dlm=","     ;
    2. 如果要读入超过8个字节的字符型变量,可以在数据步中加上一个length语句;
    3. 如果要使用输入格式,可以采用带修饰的列举模式,它的input语句类似input a $:12.;
    4. 在源数据文件中,比如是以逗号为分隔符,但文件中逗号还可能作为其中字符串的分隔符,这样就需要在infile语句中加上 dsd    ;

    最后,在实际工作中,可能需要混合使用以上几种输入模式,见汪嘉冈(2001,P.111)。

    参考资料:

    1. 汪嘉冈《SAS V8基础教程》,北京:中国统计出版社,2001
    2. SAS OnlineTutor: Basic and Intermediate SAS
    Technorati Tags:

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://johnthu.spaces.live.com/blog/cns!2053CD511E6D5B1E!378.trak
    Weblogs that reference this entry
    • None