Exporting in SAS

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 :

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  :

 

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

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 :


 

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

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 :

 

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:

 

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 :

 

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 .

 

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 .

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;

 


 

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;


 

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;

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;

 

Comments

There are no entries yet.
Please enter the code
* Required fields

Subscribe to our mailing list

* indicates required

Looking for Corporate Training ? Reach out to us at Akriti.Lal@instrovate.com

Reach out to us if you are looking for Corporate Training to Build The Next Generation Analytical Workforce with an in-depth understanding of  Exploratory Data Analysis , Data Visualisation, Data Analytics , AI First , Machine Learning & Deep Learning Training & Consulting helping them to take Data Informed Decision at each stage of the business. 

We understand that At the present times , the Entire Industry is in a Tranformation stage with the Softwares  being rebuilt with Artificial Intelligence Capabilities .

We need SMART WORKFORCE for the SMART SOFTWARES to reap the maximum return . 

 

Whatsapp at +91-9953805788 or email at - akriti.lal@instrovate.com if you would like to know more . 

 

  • Corporate Tableau Training in Gurgaon
  • Corporate Data Analytics Training in Gurgaon
  • Corporate Microsoft Power BI Training in Gurgaon
  • Corporate Microstrategy Training in Gurgaon
  • Corporate Google Data Studio Training in Gurgaon
  • Corporate Python Training in Gurgaon
  • Corporate Advance Analytics in R Programming Training in Gurgaon
  • Corporate Machine Learning Training in Gurgaon
  • Corporate Deep Learning Training in Gurgaon
  • Corporate Data Visualization Training in Gurgaon

 

Address

Instrovate Technologies

Noida, Gurgaon

 

akriti.lal@instrovate.com 

Hit Your Refresh Button To Rise Higher
Print Print | Sitemap
All rights reserved @ Instrovate Technologies
GSTIN : 09AAECI6862K1Z1

Terms Of Services    Privacy Policy    Disclaimer     Refund Policy    


Call

E-mail