Saturday, February 6, 2016

Language: SAS........

SAS is a suite of softwares for data access, transformation and reporting. Base SAS can be integrated with other components to data analysis and management. SAS is great for calculation of e.g frequency, average, forecast, regression. It can generate list, summary, graph.

Interfaces and environments: Window, GUI, Studio, Guide
Editor, log, results, explorer, view
Library has data (data has rows, columns, properties)
SAS Base data engine ( SAS7BDAT files)
e.g.
#The IMPORT procedure reads external data and writes the data to a SAS data set.
/*Comment in SAS*/
#For Microsoft Windows, use DBMS=EXCEL for transcoding. For UNIX or Linux, use DBMS=XLSX for transcoding.
do i=1 to 21 by 3;
do c=var1, var2, var3, var4;

#Submit, check log, view,  (observations in the dataset)
proc print data=sashelp.file;
run;
#html file is created
#tools...options...preferences (to change output style)

title "file_name Data";
proc print data=sashelp.file;
run;
title;
#Edit...clear all

#Data from excel file
#keyword, label, engine option
#Highlight the code and submit
libname exdat excel 'path_to_excel_file';
proc print data=exdat.'filename$'n;
run;

data work.filename;
    set exdat.'filename$'n;
where age > 20;
run;

proc import out=work.filename
            datafile="path_to_excel_file"
            dbms=excel replace;
            range="filename$'n";
run;

#Data from csv file
#Open the csv file in notepad
#firstobs=2 means start reading from row 2
data work.filename;
    infile 'path_to_file' dlm= ',' firstobs=2;
input Gender $ SATcore IDNumber TestDate $;
run;

data work.filename;
    infile 'path_to_file' dlm= ',' firstobs=2;
input Gender $ SATcore IDNumber TestDate :date9.;
run;

data work.filename;
    infile 'path_to_file' dlm= ',' firstobs=2;
input Gender $ SATcore IDNumber TestDate :date9.;
format TestDate date9.;
run;

proc import out=work.filename
            datafile="path_to_excel_file"
            dbms=csv replace;
            getnames=yes";
datarow=2;
run;

#Extracting a part of the file
#folder libsas has the file. File has many variables. Take few variables
#lowerbody is the new file made from original file. Here 5 variables have been used
libname libsas 'path_to_file';

data work.lowerbody;
      set lbsas.filename
      keep case wight height hip thigh;
run;

data work.lowerbody;
      set lbsas.filename
      drop Neck Chest Age;
run;
#import xls file to SAS library and convert to SAS file
libname here '.';
proc import datafile="file.xls" dbms=xls out=here.file replace;
run;

No comments:

Post a Comment