How to import External Data from Excel or Text file into SAS Programming?

PROC IMPORT: It is a procedure to import external files into SAS. It automates importing process. There is no need to specify the variable type and variable length to import an external file. It supports various formats of files such as excel, txt etc.

  • Importing an Excel File into SAS:

    The main keywords used in the following program are:

    1. OUT: To specify name of a data set that SAS creates. In the program below, outdata is the data set saved in work library (temporary library)
    2. DBMS: To specify the type of data to import.
    3. REPLACE: To overwrite an existing SAS data set.
    4. SHEET: To import a specific sheet from an excel workbook.
    5. GETNAMES: To include variable names from the first row of data.
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    PROC IMPORT DATAFILE= "c:\shubh\gfg.xls"
    OUT= outdata
    DBMS=xls
    REPLACE;
    SHEET="Sheet1";
    GETNAMES=YES;
    RUN;

    chevron_right

    
    

    Input:



    Output:

  • Importing a Delimited File with TXT extension:
    • To get comma separated file with a txt extension into SAS, specify delimeter = ‘, ‘
    • To get space separated file with a txt extension into SAS, specify delimeter = ‘ ‘
    • To get tab separated file with a txt extension into SAS, specify delimeter = ’09’x
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    PROC IMPORT DATAFILE= "c:\shubh\gfg.txt"
    OUT= outdata
    DBMS=dlm
    REPLACE;
    delimiter=', ';
    GETNAMES=YES;
    RUN;

    chevron_right

    
    

    Input:

    Output:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.