LOADING

Type to search

How to Export in SAS

To Know more about the Different Corporate Training & Consulting Visit our website www.Instrovate.com Or Email : info@instrovate.com or WhatsApp / Call at +91 74289 52788

Data Analytics SAS

How to Export in SAS

Share

We can export SAS dataset in external file system . We can save SAS file in text , excel or other file formats.

The syntax of PROC EXPORT is :

PROC EXPORT

DATA= SAS-data-set

OUTFILE= “filename”

DBMS=identifier

  REPLACE;

  SHEET=”Sheet-name”;

  PUTNAMES=YES;

 RUN;

1. DATA = option tells SAS to read a dataset with any name of your choice . By default , the dataset is read from WORK library .

For example , DATA = abc

In this statement , the dataset “abc” read from work library.

DATA=data.abc

In this statement , the dataset “abc” read from data library.

2. OUTFILE= option tells SAS where to store the external file that you want to export . It shows the file path from where we should export it.

For example, OUTFILE=” D:\sas\abc.xls “

3. DBMS = option tells SAS the type of file to read .

For example , DBMS= XLS for file have format “.xls ” .

DBMS= CSV for Comma Separated Value data .

4. REPLACE is used to overwrite the existing file (if stored ) in the DATA= option.

5.  SHEET = option is used to specify  which sheet SAS would export to excel file.

For example ,

SHEET = “Sheet1” – To export data to worksheet named sheet1 .

SHEET= “Data” – To export data to worksheet named Data.

6. PUTNAMES = option tells SAS to use the first row as variable names to store in data.

By default , PROC EXPORT uses PUTNAMES = YES . We can change PUTNAMES = NO , SAS would not output variable names to first row of the sheet.

 We want to export trucker dataset in CSV file . The trucker dataset is look like :

How to Export in SAS 29

The statements used are as follows :

data=trucker  tells SAS to read trucker dataset from work library .

outfile=”/home/satyamodi0/trucker.csv” tells SAS to export as trucker.csv.

dbms=csv replace tells SAS to save file in CSV format .

putnames=yes tells SAS to put variable names as first row of data file.

We write the following code to export trucker dataset as :

proc export data=trucker outfile=”/home/satyamodi0/trucker.csv” dbms=csv replace;

putnames=yes;

run;

OUTPUT:

The trucker.csv file  :

How to Export in SAS 30

We want to export examanxiety dataset stored in satya library . The dataset is look like as :

How to Export in SAS 31

We used putnames= no to not write down variables name in output file .

The following code is used to export satya.examanxiety dataset  as :

proc export data=satya.examanxiety outfile=”/home/satyamodi0/exam.csv” dbms=csv replace;

putnames=no;

run;

OUTPUT :

The exam.csv file looks like :

How to Export in SAS 32

we want to export panel dataset stored in satya library . The dataset is look like :

How to Export in SAS 33

We used following code as ;

data= satya.panle tells SAS to read panel dataset from satya library .

outfile=”/home/satyamodi0/panel.xls” tells SAS to export data in excel file .

dbms=xls tells SAS to export data in xls format.

The following code is used to export data in excel file :

proc export data=satya.panel outfile=”/home/satyamodi0/panel.xls” dbms=xls replace;

putnames=yes;

run;

OUTPUT:

The panel.xls file looks like :

How to Export in SAS 34

The following code is used to export panel dataset in xlsx file format :

proc export data=satya.panel outfile=”/home/satyamodi0/panel.xlsx” dbms=xlsx replace;

putnames=yes;

run;

OUTPUT:

How to Export in SAS 35

We can also export data to worksheet of given excel file .

sheet=”Sheet2″ tells SAS to export data to worksheet Sheet2 of panel file.

We used following code to output data in worksheet :

proc export data=satya.panel outfile=”/home/satyamodi0/panel.xlsx” dbms=xlsx replace;

putnames=yes;

sheet=”Sheet2″;

run;

OUTPUT:

The file looks like as :

How to Export in SAS 36

The following statements used as :

data= satya.panel(drop=panid) tells SAS to read panel dataset and drop panid variable .  

The code is used to do the same as :

proc export data=satya.panel(drop=panid ) outfile=”/home/satyamodi0/panel.csv” dbms=csv replace;

putnames=yes;

run;

It shows the panel.csv file with IRI_KEY , WEEK and COLUPC variables .

How to Export in SAS 37

we can keep variables in our dataset as :

proc export data=satya.panel(Keep= panid week ) outfile=”/home/satyamodi0/panel.csv” dbms=csv replace;

putnames=yes;

run;

It keeps PANID and WEEK variables in panel dataset to export in panel.csv file .

How to Export in SAS 38

We also limit the observations in our dataset . We have used obs=102 to read 102 observations from panel dataset . It will export 102 observations to panel.csv file.

proc export data=satya.panel(obs=102 ) outfile=”/home/satyamodi0/panel.csv” dbms=csv replace;

putnames=yes;

run;

How to Export in SAS 39

We want to export panel dataset starting from 29th observation . We used following code to read data from 29th observation onwards .

proc export data=satya.panel(firstobs=29 ) outfile=”/home/satyamodi0/panel.csv” dbms=csv replace;

putnames=yes;

run;

How to Export in SAS 40

It will read from 29th observation to 250th observation of panel dataset. It contains 123 observations which include 122 observations and first row shows the list of variable names.

proc export data=satya.panel(firstobs=29 obs=250) outfile=”/home/satyamodi0/panel.csv” dbms=csv replace;

putnames=yes;

run;

How to Export in SAS 41

We can rename variable names by using rename= in data statement option. It will rename PANID as pan_ID in panel.csv file.

proc export data=satya.panel(rename=(PANID=Pan_ID) ) outfile=”/home/satyamodi0/panel.csv” dbms=csv replace;

putnames=yes;

run;

How to Export in SAS 42

Previous Article
Next Article