5.IMPORT AND EXPORT OF DATASETS IN SAS

 PROC PRINT::

-->FOR TO PRINT THE ALL OBSERVATIONS AND VARIABLES FROM DATASETS

-->TO GET THE OUTPUT RESULTS OF DATASET


DATA SAS;

SET SASHELP.CLASS;

RUN;

PROC PRINT DATA=SAS;

RUN;


OPTIONS USED IN PROC PRINT:::

--VAR:: INCLUDING THE VARIABLES

--NOOBS:: REMOVE/SUPPRESS THE OBSERVATIONS COUNT NUMBER

--WHERE::TO SUBSET THE OBSERVATIONS

--TITLE::TO ENHACE THE DATASETS

--FOOTNOTES::TO ENHANCE THE DATASETS

--LABELS:;TO ENHANCE THE DATASETS

--FORMATS::TO CONTROLLING THE VALUES IN DATASETS


EG: PROC PRINT DATA=PROG1.COUNTRY;

       RUN;


USING OF 'VAR' STATEMENT::

EG1:

PROC PRINT DATA=SASHELP.CLASS;

VAR AGE NAME;

RUN;

EG2:

PROC PRINT DATA=SASHELP.CLASS;

VAR SEX;

RUN;


FOR SUPPRESSING/ELIMINATING THE OBSERVATIONS NUMBER*/

-->USE 'NOOBS' OPTION

PROC PRINT DATA=SASHELP.CLASS NOOBS;

VAR AGE NAME;

RUN;


PRINTING THE VAR BY USING ONE STARTING LETTER::

WE CAN ALSO USE ONLY ONE LETTER OF VARIABLES IN THE SYNTAX

EG1:

PROC PRINT DATA=SASHELP.CLASS;

VAR W:  ;

RUN;

EG2:

PROC PRINT DATA=SASHELP.CLASS;

VAR N:   ;

RUN;

EG3:

PROC PRINT DATA=SASHELP.CLASS;

VAR S:  ;

RUN;


DATASETS ACCESSING BY IMPORT AND EXPORT METHOD:::


1.PROC IMPORT

2.PROC EXPORT

3.PROC PRINT

4.PROC CONTENTS


4.PROC CONTENTS:::

-->   TO DISPLAY THE 'DESCRIPTOR(DESCRIBE THE SAS DATASET) PORTION' OF THE SAS DATASET

-->DATASET NAME,NUMBER OF OBSERVATIONS AND VARIABLES,LENGTH,FORMATS, INFORMATS,FILE, LOCATION ETC.

EG1:

PROC CONTENTS DATA=SASHELP.CLASS;

RUN;

EG2:

PROC CONTENTS DATA=SASHELP.HEART;

RUN;


NOTE:PROC PRINT AND CONTENTS CAN USE  FOR NEWLY CREATED DATASET/EXISTING DATASET


IMPORT AND EXPORT METHODS:::

WE CAN IMPORT AND EXPORT THE DATA BY TWO METHODS 

1.HARD CODE

2.SETUP WIZARD 


1. IMPORTING DATA::: WE CAN IMPORT THE EXCEL,TEXT AND OTHER FILES INTO                                                         'SAS ENVIRONMENT'

--->>>EXCEL FILE WILL CONVERT INTO 'RAW DATASET'

HARDCODE METHOD:::

EG1:

PROC IMPORT DATAFILE="STORAGE PATH"

             OUT=SQL.CLASS1

DBMS=XLS

REPLACE;

RUN;

EG2:

PROC IMPORT DATAFILE="C:\Users\sumed\OneDrive\Desktop\CLASS11.txt"

            OUT=SQL.BBBB

REPLACE;

RUN;


PROC IMPORT DATAFILE="C:\Users\sumed\OneDrive\Desktop\HEART.xls"

            OUT=WORK.HEART

DBMS=XLS

REPLACE;

RUN;

SETUP WIZARD METHOD:::

FIRST CLICK ON THE FILE OPTION AND SELECT THE IMPORT METHOD..

  1. Select Microsoft Excel on PC Files Server and click Next.
    Import Wizard First Panel
  2. Click Browse in the Connect to Ms Excel dialog box.
    Import Wizard Second Panel
  3. In the Files of type drop-down list, select the file extension of the Excel file:
    Select All Files
  4. Navigate to the location of the Excel file and click Open.
    Selection Menu
  5. The Import Wizard - Select table dialog box gives you a drop-down list of worksheets or tables to read. From the drop-down list, select the table that you want to read.
    Table Selection Menu
    Selecting the Table
  6. Click Options to bring up the Excel Options dialog box. These options are set by default. If you have datetime data in a column of your workbook (such as 01jan2008:08:13:22), deselect the Use DATE.format for a Date/Time column check box. Otherwise, you get only the date. You can also adjust the 1024 setting to capture column text lengths in your spreadsheet that are longer than 1024 characters. The maximum value is 32,767 characters. Click OK to close the Excel Options dialog box. Then, back on the Import Wizard - Select table dialog box, click Next.
    Options Button and Window
  7. Now select the location to store the Excel worksheet in a SAS data set. Choose the SAS libref in which you want to store the SAS data set. If you want the data set to be removed after you exit SAS, select the default WORK library. If you want the data set to remain after you exit SAS, then select another library, such as SASUSER. If the SAS data set does not exist, enter the name in the Member field of the panel. If the SAS data set already exists, choose the member to replace and click Next.
    image label
  8. The next dialog box, Import Wizard - Create SAS statements, enables you to create your own SAS PROC IMPORT code. You can do either of two things: a) Enter the full location of where you want to store the SAS code as shown in the following image:
    image label
9.Click On The Finish..

2.EXPORTING DATA:::: WE ARE EXPORTING THE RAW DATA(SAS ENVIRONMENT) TO OTHER/EXTERNAL ENVIRONMENT

 -->>RAW DATASET WILL BE CONVERTED AS EXCEL FILE

HARDCODE METHOD:::

EG1::

PROC EXPORT DATA=PROG2.DAYSALES

           OUTFILE="C:\Users\sumed\OneDrive\Desktop\DAYSALE.xls"

           DBMS=XLS 

   REPLACE;

RUN;

EG2:

PROC EXPORT DATA=SASHELP.CARS

            OUTFILE="C:\Users\sumed\OneDrive\Desktop\BOT JULY EDTORS\PROG 1\CARS.XLS"

            DBMS=XLS

           REPLACE;

RUN;

SETUP WIZARD METHOD:::

FIRST CLICK ON THE FILE OPTION AND SELECT THE EXPORT METHOD..

  1. Select File ►Export Data. A Windows dialog box will appear.

    SAS dataset selection box

    In this Windows dialog box select your SAS library libref and then select the member of the library, which is the SAS dataset. Always select the SAS library libref first. In this example we selected the SASHELP library libref and then selected a SAS dataset associated with the libref. After this is complete select the Next button.

    Select Export Type dialog box will appear as shown below:

    image label

  2. Do not select Microsoft Excel Workbook. This is for 64-bit Office.
  3. Select Microsoft Excel on PC Files Server, as shown in this image, and click Next.

    Connect to Excel dialog box will appear:

    image label

  4. There you will see a location for entering the Excel filename that you wish to export, please read the entire section here before proceeding.
  5. If the Excel file already exists you can browse to its location using the browse dialog box. The Excel file can be either a XLS, XLSX, or XLSB file.
  6. If the Excel file does not already exist you must type in the full directory path and the Excel filename you want to create. You cannot use the Browse button. You can copy the directory path using Windows Explorer.
  7. Any new Excel file must have a .XLSB extension on it. It cannot have any other extension type. This is a limitation of the Microsoft Excel ODBC driver when creating new Excel files. If you need to have a different extension, open Excel and save a default XLSX file or XLS file that SAS can use.

Using the XLSB extension

After you have entered in the name of the Excel file click on the OK and proceed to the table selection panel.

Table Selection Panel

This panel allows you to enter the name of the worksheet that you wish to add to your Excel table. If the worksheet already exists you can select the down arrow on the right to select the sheet. If the sheet does not already exist or the table does not already exist then simply type the name of the worksheet and click either Next or Finish. If you click the next button you will have the opportunity for the wizard to create a SAS program for you. If you click Finish you will proceed beyond the next panel and you are done. In this case click the Next and you will see the next panel.

Create SAS Statements

8.Click On The Finish..























Comments