SlideShare a Scribd company logo
1 of 47
*Built-in functions
*Data manipulation
*Updated often to include new applications
*Different packages complete certain tasks
more easily than others
*Packages we will introduce
*SAS
*R (S-plus)
*Easy to input and output data sets
*Preferred for data manipulation
*“proc” used to complete analyses with built-in
functions
*Macros used to build your own functions
*SAS Structure
*Efficient SAS Code for Large Files
*SAS Macro Facility
*Missing semicolon
*Misspelling
*Unmatched quotes/comments
*Mixed proc and data statement
*Using wrong options
*Data Step: input, create, manipulate or output
data
*Always start with a data line
*Ex. data one;
*Procedure Step: complete an operation on data
*Always start with a proc line
*Ex. proc contents;
*System options are global instructions that
affect the entire SAS session and control the
way SAS performs operations. SAS system
options differ from SAS data set options and
statement options in that once you invoke a
system option, it remains in effect for all
subsequent data and proc steps in a SAS job,
unless you specify them.
*In order to view which options are available and
in effect for your SAS session, use proc options;
run;
* center controls whether SAS procedure output is centered. By default, output is
centered. To specify not centered, use nocenter.
* date prints the date and time to the log and output window. By default, the date and
time is printed. To suppress the printing of the date, use nodate.
* label allows SAS procedures to use labels with variables. By default, labels are
permitted. To suppress the printing of labels, use nolabel.
* notes controls whether notes are printed to the SAS log. By default, notes are printed.
To suppress the printing of notes, use nonotes.
* number controls whether page numbers are printed. By default, page numbers are
printed. To suppress the printing of page numbers, use nonumber.
* linesize= specifies the line size (printer line width) for the SAS log and the SAS
procedure output file used by the data step and procedures.
* pagesize= specifies # of lines that can be printed per page of SAS output.
* missing= specifies the character to be printed for missing numeric values.
* formchar= specifies the the list of graphics characters that define table boundaries.
Example:
OPTIONS NOCENTER NODATE NONOTES LINESIZE=80 MISSING=. ;
SAS data set control options specify how SAS data
sets are input, processed, and output.
*firstobs= causes SAS to begin reading at a specified observation in a
data set. The default is firstobs=1.
*obs= specifies the last observation from a data set or the last
record from a raw data file that SAS is to read. To return to using
all observations in a data set use obs=all
*replace specifies whether permanently stored SAS data sets are to
be replaced. By default, the SAS system will over-write existing SAS
data sets if the SAS data set is re-specified in a data step. To
suppress this option, use noreplace.
Example:
*OPTIONS OBS=100 NOREPLACE;
Error handling options specify how the SAS System
reports on and recovers from error conditions.
* errors= controls the maximum number of observations for which
complete error messages are printed. The default maximum number
of complete error messages is errors=20
* fmterr controls whether the SAS System generates an error message
when the system cannot find a format to associate with a variable.
SAS will generate an ERROR message for every unknown format it
encounters and will terminate the SAS job without running any
following data and proc steps. To read a SAS system data set without
requiring a SAS format library, use nofmterr.
Example:
OPTIONS ERRORS=100 NOFMTERR;
*data statement names the data set you are
making
*Can use any of the following commands to
input data
*infile Identifies an external raw data file to read
with an INPUT statement
*input Lists variable names in the input file
*cards Indicates internal data
*set Reads a SAS data set
*To look at the variables in a data set, use
*proc contents data=dataset;
run;
*To look at the actual data in the data set,
*proc print data=dataset (obs=num);
var varlist;
run;
data treat;
infile “g:sharedBIO271treat.dat”;
input id bpa bpb chola cholb;
run;
proc print data = treat (obs=10);
run;
proc contents data=treat;
run;
*blank space (default)
*DELIMITER= option specifies that the INPUT
statement use a character other than a blank
as a delimiter for data values that are read
with list input
Sometimes you want to input the data yourself
Try the following data step:
data nums;
infile datalines dsd delimiter=‘&';
input X Y Z;
datalines;
1&2&3
4&5&6
7&8&9 ;
Notice that there are no semicolons until the
end of the datalines
*Another way to input data using the
keyboard (and often a last resort if having
problems input the data) is cards
*Similar to datalines
*data score;
input test1 test2 test3;
cards;
91 87 95
97 . 92
. 89 99
;
run;
*Sometimes your data will have characters
*Example:
data fam;
input name$ age;
cards;
Brian 27
Andrew 29
Kate 24
run;
proc print data=fam;
run;
*What is different and what happens if you
don’t have the dollar sign?
*The final way we will show to input data is if
you have a SAS data set , you can use a
libname command
libname summer "g:sharedbio271";
data treat2;
set summer.treat2;
run;
*Look at the data set with proc print
Variable label: Use the label statement in the data step
to assign labels to the variables.  You could also assign
labels to variables in proc steps, but then the labels only
exist for that step.  When labels are assigned in the data
step they are available for all procedures that use that
data set.
Example:
DATA labtreat;
SET treat;
LABEL id=“patient id” bpa =“BP on treatment A" bpb =“BP on treatment B"
cholA=“Cholesterol on treatment A” cholB=“Cholesterol on treatment B";
RUN;
PROC CONTENTS DATA=labtreat;
RUN;
*Make a data set with the following data calling
it redsox
*8, 58, 491, 163
7, 50, 469, 133
31, 107, 458, 136
33, 111, 410, 117
*Label the variables HR, RBI, AB, HITS
*Use proc print to ensure that you have input
the data correctly
*One of the best parts of SAS is the ability to complete data
manipulations
*There are four major types of manipulations
*Subset of data
*Drop / keep variables
*Drop observations
*Concatenate data files
*Merge data files
*Create new variables
*SAS easily allows you to make a data set
with a subset of the variables
*What do you think happens with this code?
DATA redsox2;
SET redsox;
KEEP ba rbi;
RUN;
*How do you think you could use drop to do
the same thing?
*We can also get a subset of the observations
*Read in treat2 from the g: drive
*This is helpful when we want to remove
missing data
DATA notreat2;
SET treat2;
IF cholA ^= . ;
RUN;
*SAS allows us to combine dataset by adding
more observations, using
data tottreat;
set treat treat2;
run;
*Check that it worked using proc print
*If a variable is called by a different name in
each dataset, you must use:
data momdad;
set dads(RENAME=(dadinc=inc)) moms(RENAME=(mominc=inc));
run;
*SAS also allows us to add more variables by merging
data files
*The data set demo gives demographic information
about the patients in treat
*Read in demo
*Now, use this code to combine the information
data extratreat;
merge treat demo;
by id;
run;
*Note: the data in each data set must be sorted to
use this code
*We can make new variables in a data step
*Let’s make a new variable in the redsox data set by
finding batting average and a variable for hr30
data redsox2;
set redsox;
ba=hits/ab;
if hr>=30 then hr30=1 else hr30=0;
run;
*Make a new data set called redsox3 using the
following data and combine it with redsox
7, 51, 378, 113
4, 41, 367, 99
20, 58, 361, 109
*Make a new variable in redsox3 that equals 1 if
rbi is more than 100 and 0 if rib is less than or
equal to 100
*file: Specifies the current output file for PUT
statements
*put: Writes lines to the SAS log, to the SAS
procedure output file, or to an external file
that is specified in the most recent FILE
statement.
Example:
data _null_;
set redsox;
file ‘p:redsox.csv' delimiter=',' dsd;
put hr rbi ab hits;
run;
*The INFILE statement specifies the input file for
any INPUT statements in the DATA step. The FILE
statement specifies the output file for any PUT
statements in the DATA step.
*Both the FILE and INFILE statements allow you to
use options that provide SAS with additional
information about the external file being used.
*An INFILE statement usually identifies data from an
external file. A DATALINES statement indicates that
data follow in the job stream. You can use the
INFILE statement with the file specification
DATALINES to take advantage of certain data-
reading options that effect how the INPUT
statement reads in-stream data.
*Missing values in SAS are shown by .
*As a general rule, SAS procedures that perform
computations handle missing data by omitting
the missing values, including proc means, proc
freq, proc corr, and proc reg
*Check SAS web page for more information
* SAS treats a missing value as the smallest
possible value (e.g., negative infinity) in
logical statements.
data times6;
set times ;
if (var1 <= 1.5) then varc1 = 0; else varc1 = 1 ;
run ;
Output:
Obs id var1 varc1
1 1 1.5 0
2 2 . 0
3 3 2.1 1
*proc print and proc contents- we have seen
these
*proc sort
*proc means
*proc univariate
*proc plot
*var: lists the variables you want to perform the
proc on
*by: breaks the data into groups
*where: limits the data set to a specific group
of observations
*output: allows you to output the results into a
data set
*We can use proc sort to sort data
*The code to complete this is
proc sort data=extratreat ; by gender ; run ;
proc sort data=extratreat out=extreat ; by gender ; run ;
proc sort data=extratreat out=extreat2; by descending
gender ; run ;
proc sort data=extratreat out=extreat3 noduplicates;
by gender ; run ;
*The basic form of proc means is
*proc means data=extratreat;
var ______;
by _______;
where _______;
output out=stat mean=bpamean cholamean;
run;
*The basic form of proc univariate is the
same, but much more information is given
*It is helpful to use the output window to
get the info you need
*To make different plots in SAS, you use
proc plot
*Scatterplot
*proc plot data=redsox;
plot rbi*ab;
run;
*You can also make plots using
*proc univariate data=redsox plot;
var rbi;
run;
*Find the mean blood pressure on treatment A
in women
*Make a scatterplot of blood pressure on
treatment B versus blood pressure on
treatment A in men
*Find the median number of home runs hit by
the Red Sox
Macros are the SAS method of making functions
*Avoid repetitious SAS code
*Create generalizable and flexible SAS code
*Pass information from one part of a SAS job to
another
*Conditionally execute data steps and PROCs
*SAS macro variable
*SAS Macro
*There are many discussions of macro variables
on the web; one good one is given here:
http://www2.sas.com/proceedings/sugi30/130
-30.pdf
Two delimiters will trigger the macro
processor in a SAS program.
*&macro-variable
This refers to a macro variable. The current
value of the variable will replace &macro-variable;
*%macro-name
This refers to a macro, which consists of one or
more complete SAS statements, or even whole data
or proc steps.
*SAS Macro variables can be defined and used
anywhere in a SAS program, except in data
lines. They are independent of a SAS dataset.
%LET: assign text to a macro variable;
%LET macrovar = value
1. Macrovar is the name of a global macro variable;
2. Value is macro variable value, which is a character
string without quotation or macro expression.
%PUT: display macro variable values as text
in the SAS log; %put _all_, %put _user_
&macrovar: Substitute the value of a macro
variable in a program;
*Here is an example of how to use a macro variable:
*%let int=treat;
proc means data=&int;
run;
*Now we can rerun the code again simply changing the
value of the macro variable, without altering the rest
of the code.
*%let int=redsox;
proc means data=&int;
run;
*This is extremely helpful when you have a large
amount of code you want to reference
*Definition:
%MACRO macro-name (parm1, parm2,…parmk);
Macro definition (&parm1,&parm2,…&parmk)
%MEND macro-name;
*Application:
%macro-name(values of parm1, parm2,…,parmk);
Import Excel to SAS Datasets by a Macro
%macro excelsas(in, out);
proc import out=work.&out
datafile=“g:sharedbio271&in"
dbms=excel replace;
getnames=yes; run;
%mend excelsas;
% excelsas(practice.xls,test)
Use proc print to ensure that you have the data
input properly
%let int=treat;
%let dop=%str(id bpa);
%macro happy;
data new;
set &int;
drop &dop;
run;
proc means data=new;
run;
%mend happy;
%happy
Sas-training-in-mumbai

More Related Content

What's hot

Export Data using R Studio
Export Data using R StudioExport Data using R Studio
Export Data using R StudioRupak Roy
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq lsInSync Conference
 
Import Data using R
Import Data using R Import Data using R
Import Data using R Rupak Roy
 
Stata Cheat Sheets (all)
Stata Cheat Sheets (all)Stata Cheat Sheets (all)
Stata Cheat Sheets (all)Laura Hughes
 
Data Warehouse and Business Intelligence - Recipe 4 - Staging area - how to v...
Data Warehouse and Business Intelligence - Recipe 4 - Staging area - how to v...Data Warehouse and Business Intelligence - Recipe 4 - Staging area - how to v...
Data Warehouse and Business Intelligence - Recipe 4 - Staging area - how to v...Massimo Cenci
 
Postgresql Database Administration- Day3
Postgresql Database Administration- Day3Postgresql Database Administration- Day3
Postgresql Database Administration- Day3PoguttuezhiniVP
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007paulguerin
 
Recipe 5 of Data Warehouse and Business Intelligence - The null values manage...
Recipe 5 of Data Warehouse and Business Intelligence - The null values manage...Recipe 5 of Data Warehouse and Business Intelligence - The null values manage...
Recipe 5 of Data Warehouse and Business Intelligence - The null values manage...Massimo Cenci
 
Data Warehouse and Business Intelligence - Recipe 7 - A messaging system for ...
Data Warehouse and Business Intelligence - Recipe 7 - A messaging system for ...Data Warehouse and Business Intelligence - Recipe 7 - A messaging system for ...
Data Warehouse and Business Intelligence - Recipe 7 - A messaging system for ...Massimo Cenci
 
Prog1 chap1 and chap 2
Prog1 chap1 and chap 2Prog1 chap1 and chap 2
Prog1 chap1 and chap 2rowensCap
 
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
Aaa ped-6-Data manipulation:  Data Files, and Data Cleaning & PreparationAaa ped-6-Data manipulation:  Data Files, and Data Cleaning & Preparation
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & PreparationAminaRepo
 
R hive tutorial - apply functions and map reduce
R hive tutorial - apply functions and map reduceR hive tutorial - apply functions and map reduce
R hive tutorial - apply functions and map reduceAiden Seonghak Hong
 

What's hot (20)

Export Data using R Studio
Export Data using R StudioExport Data using R Studio
Export Data using R Studio
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
 
Arrays in SAS
Arrays in SASArrays in SAS
Arrays in SAS
 
Import Data using R
Import Data using R Import Data using R
Import Data using R
 
Sas practice programs
Sas practice programsSas practice programs
Sas practice programs
 
Comparing SAS Files
Comparing SAS FilesComparing SAS Files
Comparing SAS Files
 
Oracle sql loader utility
Oracle sql loader utilityOracle sql loader utility
Oracle sql loader utility
 
Stata Cheat Sheets (all)
Stata Cheat Sheets (all)Stata Cheat Sheets (all)
Stata Cheat Sheets (all)
 
Sql loader good example
Sql loader good exampleSql loader good example
Sql loader good example
 
Data Warehouse and Business Intelligence - Recipe 4 - Staging area - how to v...
Data Warehouse and Business Intelligence - Recipe 4 - Staging area - how to v...Data Warehouse and Business Intelligence - Recipe 4 - Staging area - how to v...
Data Warehouse and Business Intelligence - Recipe 4 - Staging area - how to v...
 
Postgresql Database Administration- Day3
Postgresql Database Administration- Day3Postgresql Database Administration- Day3
Postgresql Database Administration- Day3
 
R Get Started I
R Get Started IR Get Started I
R Get Started I
 
R Get Started II
R Get Started IIR Get Started II
R Get Started II
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
 
Recipe 5 of Data Warehouse and Business Intelligence - The null values manage...
Recipe 5 of Data Warehouse and Business Intelligence - The null values manage...Recipe 5 of Data Warehouse and Business Intelligence - The null values manage...
Recipe 5 of Data Warehouse and Business Intelligence - The null values manage...
 
Data Warehouse and Business Intelligence - Recipe 7 - A messaging system for ...
Data Warehouse and Business Intelligence - Recipe 7 - A messaging system for ...Data Warehouse and Business Intelligence - Recipe 7 - A messaging system for ...
Data Warehouse and Business Intelligence - Recipe 7 - A messaging system for ...
 
Prog1 chap1 and chap 2
Prog1 chap1 and chap 2Prog1 chap1 and chap 2
Prog1 chap1 and chap 2
 
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
Aaa ped-6-Data manipulation:  Data Files, and Data Cleaning & PreparationAaa ped-6-Data manipulation:  Data Files, and Data Cleaning & Preparation
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
 
DataBase Management System Lab File
DataBase Management System Lab FileDataBase Management System Lab File
DataBase Management System Lab File
 
R hive tutorial - apply functions and map reduce
R hive tutorial - apply functions and map reduceR hive tutorial - apply functions and map reduce
R hive tutorial - apply functions and map reduce
 

Viewers also liked

Universal Design
Universal Design Universal Design
Universal Design Scott Levy
 
2012アーバニズム_B1_政治家の生んだ都市_高橋樹_11N1082
2012アーバニズム_B1_政治家の生んだ都市_高橋樹_11N10822012アーバニズム_B1_政治家の生んだ都市_高橋樹_11N1082
2012アーバニズム_B1_政治家の生んだ都市_高橋樹_11N108211N1082
 
UNIT 7 INTERIORS
UNIT 7 INTERIORSUNIT 7 INTERIORS
UNIT 7 INTERIORSshilpi roy
 
IDCC 172 Accord formation professionnelle
IDCC 172 Accord formation professionnelle IDCC 172 Accord formation professionnelle
IDCC 172 Accord formation professionnelle Société Tripalio
 
How to Create a Winning Recruitment Strategy
How to Create a Winning Recruitment StrategyHow to Create a Winning Recruitment Strategy
How to Create a Winning Recruitment StrategyCareerBuilder
 
土壌微生物によるバイオクロッギングの温度依存性について
土壌微生物によるバイオクロッギングの温度依存性について�土壌微生物によるバイオクロッギングの温度依存性について�
土壌微生物によるバイオクロッギングの温度依存性についてKatsutoshi Seki
 
noreply@utah.gov_20160224_110554-2
noreply@utah.gov_20160224_110554-2noreply@utah.gov_20160224_110554-2
noreply@utah.gov_20160224_110554-2Ryan B. Whitesides
 
The stone age
The stone ageThe stone age
The stone ageHST130mcc
 
PhD_dissertation_Niels_Erik_Olesen
PhD_dissertation_Niels_Erik_OlesenPhD_dissertation_Niels_Erik_Olesen
PhD_dissertation_Niels_Erik_OlesenNiels Erik Olesen
 

Viewers also liked (17)

Mikey CV Final
Mikey CV FinalMikey CV Final
Mikey CV Final
 
Ppweb
PpwebPpweb
Ppweb
 
word
wordword
word
 
Universal Design
Universal Design Universal Design
Universal Design
 
Pepipost - Product Overview
Pepipost - Product OverviewPepipost - Product Overview
Pepipost - Product Overview
 
2012アーバニズム_B1_政治家の生んだ都市_高橋樹_11N1082
2012アーバニズム_B1_政治家の生んだ都市_高橋樹_11N10822012アーバニズム_B1_政治家の生んだ都市_高橋樹_11N1082
2012アーバニズム_B1_政治家の生んだ都市_高橋樹_11N1082
 
Strona internetowa firmy
Strona internetowa firmyStrona internetowa firmy
Strona internetowa firmy
 
Question two
Question twoQuestion two
Question two
 
mapa conceptual
mapa conceptualmapa conceptual
mapa conceptual
 
UNIT 7 INTERIORS
UNIT 7 INTERIORSUNIT 7 INTERIORS
UNIT 7 INTERIORS
 
IDCC 172 Accord formation professionnelle
IDCC 172 Accord formation professionnelle IDCC 172 Accord formation professionnelle
IDCC 172 Accord formation professionnelle
 
You've been framed
You've been framedYou've been framed
You've been framed
 
How to Create a Winning Recruitment Strategy
How to Create a Winning Recruitment StrategyHow to Create a Winning Recruitment Strategy
How to Create a Winning Recruitment Strategy
 
土壌微生物によるバイオクロッギングの温度依存性について
土壌微生物によるバイオクロッギングの温度依存性について�土壌微生物によるバイオクロッギングの温度依存性について�
土壌微生物によるバイオクロッギングの温度依存性について
 
noreply@utah.gov_20160224_110554-2
noreply@utah.gov_20160224_110554-2noreply@utah.gov_20160224_110554-2
noreply@utah.gov_20160224_110554-2
 
The stone age
The stone ageThe stone age
The stone age
 
PhD_dissertation_Niels_Erik_Olesen
PhD_dissertation_Niels_Erik_OlesenPhD_dissertation_Niels_Erik_Olesen
PhD_dissertation_Niels_Erik_Olesen
 

Similar to Sas-training-in-mumbai

Introduction to-sas-1211594349119006-8
Introduction to-sas-1211594349119006-8Introduction to-sas-1211594349119006-8
Introduction to-sas-1211594349119006-8thotakoti
 
Introduction To Sas
Introduction To SasIntroduction To Sas
Introduction To Sashalasti
 
SAS cheat sheet
SAS cheat sheetSAS cheat sheet
SAS cheat sheetAli Ajouz
 
Introducción al Software Analítico SAS
Introducción al Software Analítico SASIntroducción al Software Analítico SAS
Introducción al Software Analítico SASJorge Rodríguez M.
 
I need help with Applied Statistics and the SAS Programming Language.pdf
I need help with Applied Statistics and the SAS Programming Language.pdfI need help with Applied Statistics and the SAS Programming Language.pdf
I need help with Applied Statistics and the SAS Programming Language.pdfMadansilks
 
Data Match Merging in SAS
Data Match Merging in SASData Match Merging in SAS
Data Match Merging in SASguest2160992
 
Basics Of SAS Programming Language
Basics Of SAS Programming LanguageBasics Of SAS Programming Language
Basics Of SAS Programming Languageguest2160992
 
Understanding SAS Data Step Processing
Understanding SAS Data Step ProcessingUnderstanding SAS Data Step Processing
Understanding SAS Data Step Processingguest2160992
 
Draft sas and r and sas (may, 2018 asa meeting)
Draft sas and r and sas (may, 2018 asa meeting)Draft sas and r and sas (may, 2018 asa meeting)
Draft sas and r and sas (may, 2018 asa meeting)Barry DeCicco
 

Similar to Sas-training-in-mumbai (20)

Introduction to-sas-1211594349119006-8
Introduction to-sas-1211594349119006-8Introduction to-sas-1211594349119006-8
Introduction to-sas-1211594349119006-8
 
SAS - Training
SAS - Training SAS - Training
SAS - Training
 
Introduction To Sas
Introduction To SasIntroduction To Sas
Introduction To Sas
 
SAS Commands
SAS CommandsSAS Commands
SAS Commands
 
Sas classes in mumbai
Sas classes in mumbaiSas classes in mumbai
Sas classes in mumbai
 
SAS cheat sheet
SAS cheat sheetSAS cheat sheet
SAS cheat sheet
 
Introducción al Software Analítico SAS
Introducción al Software Analítico SASIntroducción al Software Analítico SAS
Introducción al Software Analítico SAS
 
I need help with Applied Statistics and the SAS Programming Language.pdf
I need help with Applied Statistics and the SAS Programming Language.pdfI need help with Applied Statistics and the SAS Programming Language.pdf
I need help with Applied Statistics and the SAS Programming Language.pdf
 
Data Match Merging in SAS
Data Match Merging in SASData Match Merging in SAS
Data Match Merging in SAS
 
SAS Programming Notes
SAS Programming NotesSAS Programming Notes
SAS Programming Notes
 
Basics Of SAS Programming Language
Basics Of SAS Programming LanguageBasics Of SAS Programming Language
Basics Of SAS Programming Language
 
SAS - overview of SAS
SAS - overview of SASSAS - overview of SAS
SAS - overview of SAS
 
Sas summary guide
Sas summary guideSas summary guide
Sas summary guide
 
SAS Online Training by Real Time Working Professionals in USA,UK,India,Middle...
SAS Online Training by Real Time Working Professionals in USA,UK,India,Middle...SAS Online Training by Real Time Working Professionals in USA,UK,India,Middle...
SAS Online Training by Real Time Working Professionals in USA,UK,India,Middle...
 
Understanding SAS Data Step Processing
Understanding SAS Data Step ProcessingUnderstanding SAS Data Step Processing
Understanding SAS Data Step Processing
 
Draft sas and r and sas (may, 2018 asa meeting)
Draft sas and r and sas (may, 2018 asa meeting)Draft sas and r and sas (may, 2018 asa meeting)
Draft sas and r and sas (may, 2018 asa meeting)
 
Aggregate.pptx
Aggregate.pptxAggregate.pptx
Aggregate.pptx
 
R stata
R stataR stata
R stata
 
Sas
SasSas
Sas
 
07.bootstrapping
07.bootstrapping07.bootstrapping
07.bootstrapping
 

More from Unmesh Baile

java-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbaijava-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbaiUnmesh Baile
 
Php mysql training-in-mumbai
Php mysql training-in-mumbaiPhp mysql training-in-mumbai
Php mysql training-in-mumbaiUnmesh Baile
 
Java course-in-mumbai
Java course-in-mumbaiJava course-in-mumbai
Java course-in-mumbaiUnmesh Baile
 
Robotics corporate-training-in-mumbai
Robotics corporate-training-in-mumbaiRobotics corporate-training-in-mumbai
Robotics corporate-training-in-mumbaiUnmesh Baile
 
Corporate-training-for-msbi-course-in-mumbai
Corporate-training-for-msbi-course-in-mumbaiCorporate-training-for-msbi-course-in-mumbai
Corporate-training-for-msbi-course-in-mumbaiUnmesh Baile
 
Linux corporate-training-in-mumbai
Linux corporate-training-in-mumbaiLinux corporate-training-in-mumbai
Linux corporate-training-in-mumbaiUnmesh Baile
 
Professional dataware-housing-training-in-mumbai
Professional dataware-housing-training-in-mumbaiProfessional dataware-housing-training-in-mumbai
Professional dataware-housing-training-in-mumbaiUnmesh Baile
 
Best-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbaiBest-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbaiUnmesh Baile
 
Selenium-corporate-training-in-mumbai
Selenium-corporate-training-in-mumbaiSelenium-corporate-training-in-mumbai
Selenium-corporate-training-in-mumbaiUnmesh Baile
 
Weblogic-clustering-failover-and-load-balancing-training
Weblogic-clustering-failover-and-load-balancing-trainingWeblogic-clustering-failover-and-load-balancing-training
Weblogic-clustering-failover-and-load-balancing-trainingUnmesh Baile
 
Advance-excel-professional-trainer-in-mumbai
Advance-excel-professional-trainer-in-mumbaiAdvance-excel-professional-trainer-in-mumbai
Advance-excel-professional-trainer-in-mumbaiUnmesh Baile
 
Best corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbaiBest corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbaiUnmesh Baile
 
R-programming-training-in-mumbai
R-programming-training-in-mumbaiR-programming-training-in-mumbai
R-programming-training-in-mumbaiUnmesh Baile
 
Corporate-data-warehousing-training
Corporate-data-warehousing-trainingCorporate-data-warehousing-training
Corporate-data-warehousing-trainingUnmesh Baile
 
Microsoft-business-intelligence-training-in-mumbai
Microsoft-business-intelligence-training-in-mumbaiMicrosoft-business-intelligence-training-in-mumbai
Microsoft-business-intelligence-training-in-mumbaiUnmesh Baile
 
Linux-training-for-beginners-in-mumbai
Linux-training-for-beginners-in-mumbaiLinux-training-for-beginners-in-mumbai
Linux-training-for-beginners-in-mumbaiUnmesh Baile
 
Corporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbaiCorporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbaiUnmesh Baile
 
Corporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbaiCorporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbaiUnmesh Baile
 
Best-robotics-training-in-mumbai
Best-robotics-training-in-mumbaiBest-robotics-training-in-mumbai
Best-robotics-training-in-mumbaiUnmesh Baile
 
Best-embedded-system-classes-in-mumbai
Best-embedded-system-classes-in-mumbaiBest-embedded-system-classes-in-mumbai
Best-embedded-system-classes-in-mumbaiUnmesh Baile
 

More from Unmesh Baile (20)

java-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbaijava-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbai
 
Php mysql training-in-mumbai
Php mysql training-in-mumbaiPhp mysql training-in-mumbai
Php mysql training-in-mumbai
 
Java course-in-mumbai
Java course-in-mumbaiJava course-in-mumbai
Java course-in-mumbai
 
Robotics corporate-training-in-mumbai
Robotics corporate-training-in-mumbaiRobotics corporate-training-in-mumbai
Robotics corporate-training-in-mumbai
 
Corporate-training-for-msbi-course-in-mumbai
Corporate-training-for-msbi-course-in-mumbaiCorporate-training-for-msbi-course-in-mumbai
Corporate-training-for-msbi-course-in-mumbai
 
Linux corporate-training-in-mumbai
Linux corporate-training-in-mumbaiLinux corporate-training-in-mumbai
Linux corporate-training-in-mumbai
 
Professional dataware-housing-training-in-mumbai
Professional dataware-housing-training-in-mumbaiProfessional dataware-housing-training-in-mumbai
Professional dataware-housing-training-in-mumbai
 
Best-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbaiBest-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbai
 
Selenium-corporate-training-in-mumbai
Selenium-corporate-training-in-mumbaiSelenium-corporate-training-in-mumbai
Selenium-corporate-training-in-mumbai
 
Weblogic-clustering-failover-and-load-balancing-training
Weblogic-clustering-failover-and-load-balancing-trainingWeblogic-clustering-failover-and-load-balancing-training
Weblogic-clustering-failover-and-load-balancing-training
 
Advance-excel-professional-trainer-in-mumbai
Advance-excel-professional-trainer-in-mumbaiAdvance-excel-professional-trainer-in-mumbai
Advance-excel-professional-trainer-in-mumbai
 
Best corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbaiBest corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbai
 
R-programming-training-in-mumbai
R-programming-training-in-mumbaiR-programming-training-in-mumbai
R-programming-training-in-mumbai
 
Corporate-data-warehousing-training
Corporate-data-warehousing-trainingCorporate-data-warehousing-training
Corporate-data-warehousing-training
 
Microsoft-business-intelligence-training-in-mumbai
Microsoft-business-intelligence-training-in-mumbaiMicrosoft-business-intelligence-training-in-mumbai
Microsoft-business-intelligence-training-in-mumbai
 
Linux-training-for-beginners-in-mumbai
Linux-training-for-beginners-in-mumbaiLinux-training-for-beginners-in-mumbai
Linux-training-for-beginners-in-mumbai
 
Corporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbaiCorporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbai
 
Corporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbaiCorporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbai
 
Best-robotics-training-in-mumbai
Best-robotics-training-in-mumbaiBest-robotics-training-in-mumbai
Best-robotics-training-in-mumbai
 
Best-embedded-system-classes-in-mumbai
Best-embedded-system-classes-in-mumbaiBest-embedded-system-classes-in-mumbai
Best-embedded-system-classes-in-mumbai
 

Recently uploaded

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 

Recently uploaded (20)

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 

Sas-training-in-mumbai

  • 1.
  • 2. *Built-in functions *Data manipulation *Updated often to include new applications *Different packages complete certain tasks more easily than others *Packages we will introduce *SAS *R (S-plus)
  • 3. *Easy to input and output data sets *Preferred for data manipulation *“proc” used to complete analyses with built-in functions *Macros used to build your own functions
  • 4. *SAS Structure *Efficient SAS Code for Large Files *SAS Macro Facility
  • 5. *Missing semicolon *Misspelling *Unmatched quotes/comments *Mixed proc and data statement *Using wrong options
  • 6. *Data Step: input, create, manipulate or output data *Always start with a data line *Ex. data one; *Procedure Step: complete an operation on data *Always start with a proc line *Ex. proc contents;
  • 7. *System options are global instructions that affect the entire SAS session and control the way SAS performs operations. SAS system options differ from SAS data set options and statement options in that once you invoke a system option, it remains in effect for all subsequent data and proc steps in a SAS job, unless you specify them. *In order to view which options are available and in effect for your SAS session, use proc options; run;
  • 8. * center controls whether SAS procedure output is centered. By default, output is centered. To specify not centered, use nocenter. * date prints the date and time to the log and output window. By default, the date and time is printed. To suppress the printing of the date, use nodate. * label allows SAS procedures to use labels with variables. By default, labels are permitted. To suppress the printing of labels, use nolabel. * notes controls whether notes are printed to the SAS log. By default, notes are printed. To suppress the printing of notes, use nonotes. * number controls whether page numbers are printed. By default, page numbers are printed. To suppress the printing of page numbers, use nonumber. * linesize= specifies the line size (printer line width) for the SAS log and the SAS procedure output file used by the data step and procedures. * pagesize= specifies # of lines that can be printed per page of SAS output. * missing= specifies the character to be printed for missing numeric values. * formchar= specifies the the list of graphics characters that define table boundaries. Example: OPTIONS NOCENTER NODATE NONOTES LINESIZE=80 MISSING=. ;
  • 9. SAS data set control options specify how SAS data sets are input, processed, and output. *firstobs= causes SAS to begin reading at a specified observation in a data set. The default is firstobs=1. *obs= specifies the last observation from a data set or the last record from a raw data file that SAS is to read. To return to using all observations in a data set use obs=all *replace specifies whether permanently stored SAS data sets are to be replaced. By default, the SAS system will over-write existing SAS data sets if the SAS data set is re-specified in a data step. To suppress this option, use noreplace. Example: *OPTIONS OBS=100 NOREPLACE;
  • 10. Error handling options specify how the SAS System reports on and recovers from error conditions. * errors= controls the maximum number of observations for which complete error messages are printed. The default maximum number of complete error messages is errors=20 * fmterr controls whether the SAS System generates an error message when the system cannot find a format to associate with a variable. SAS will generate an ERROR message for every unknown format it encounters and will terminate the SAS job without running any following data and proc steps. To read a SAS system data set without requiring a SAS format library, use nofmterr. Example: OPTIONS ERRORS=100 NOFMTERR;
  • 11. *data statement names the data set you are making *Can use any of the following commands to input data *infile Identifies an external raw data file to read with an INPUT statement *input Lists variable names in the input file *cards Indicates internal data *set Reads a SAS data set
  • 12. *To look at the variables in a data set, use *proc contents data=dataset; run; *To look at the actual data in the data set, *proc print data=dataset (obs=num); var varlist; run;
  • 13. data treat; infile “g:sharedBIO271treat.dat”; input id bpa bpb chola cholb; run; proc print data = treat (obs=10); run; proc contents data=treat; run;
  • 14. *blank space (default) *DELIMITER= option specifies that the INPUT statement use a character other than a blank as a delimiter for data values that are read with list input
  • 15. Sometimes you want to input the data yourself Try the following data step: data nums; infile datalines dsd delimiter=‘&'; input X Y Z; datalines; 1&2&3 4&5&6 7&8&9 ; Notice that there are no semicolons until the end of the datalines
  • 16. *Another way to input data using the keyboard (and often a last resort if having problems input the data) is cards *Similar to datalines *data score; input test1 test2 test3; cards; 91 87 95 97 . 92 . 89 99 ; run;
  • 17. *Sometimes your data will have characters *Example: data fam; input name$ age; cards; Brian 27 Andrew 29 Kate 24 run; proc print data=fam; run; *What is different and what happens if you don’t have the dollar sign?
  • 18. *The final way we will show to input data is if you have a SAS data set , you can use a libname command libname summer "g:sharedbio271"; data treat2; set summer.treat2; run; *Look at the data set with proc print
  • 19. Variable label: Use the label statement in the data step to assign labels to the variables.  You could also assign labels to variables in proc steps, but then the labels only exist for that step.  When labels are assigned in the data step they are available for all procedures that use that data set. Example: DATA labtreat; SET treat; LABEL id=“patient id” bpa =“BP on treatment A" bpb =“BP on treatment B" cholA=“Cholesterol on treatment A” cholB=“Cholesterol on treatment B"; RUN; PROC CONTENTS DATA=labtreat; RUN;
  • 20. *Make a data set with the following data calling it redsox *8, 58, 491, 163 7, 50, 469, 133 31, 107, 458, 136 33, 111, 410, 117 *Label the variables HR, RBI, AB, HITS *Use proc print to ensure that you have input the data correctly
  • 21. *One of the best parts of SAS is the ability to complete data manipulations *There are four major types of manipulations *Subset of data *Drop / keep variables *Drop observations *Concatenate data files *Merge data files *Create new variables
  • 22. *SAS easily allows you to make a data set with a subset of the variables *What do you think happens with this code? DATA redsox2; SET redsox; KEEP ba rbi; RUN; *How do you think you could use drop to do the same thing?
  • 23. *We can also get a subset of the observations *Read in treat2 from the g: drive *This is helpful when we want to remove missing data DATA notreat2; SET treat2; IF cholA ^= . ; RUN;
  • 24. *SAS allows us to combine dataset by adding more observations, using data tottreat; set treat treat2; run; *Check that it worked using proc print *If a variable is called by a different name in each dataset, you must use: data momdad; set dads(RENAME=(dadinc=inc)) moms(RENAME=(mominc=inc)); run;
  • 25. *SAS also allows us to add more variables by merging data files *The data set demo gives demographic information about the patients in treat *Read in demo *Now, use this code to combine the information data extratreat; merge treat demo; by id; run; *Note: the data in each data set must be sorted to use this code
  • 26. *We can make new variables in a data step *Let’s make a new variable in the redsox data set by finding batting average and a variable for hr30 data redsox2; set redsox; ba=hits/ab; if hr>=30 then hr30=1 else hr30=0; run;
  • 27. *Make a new data set called redsox3 using the following data and combine it with redsox 7, 51, 378, 113 4, 41, 367, 99 20, 58, 361, 109 *Make a new variable in redsox3 that equals 1 if rbi is more than 100 and 0 if rib is less than or equal to 100
  • 28. *file: Specifies the current output file for PUT statements *put: Writes lines to the SAS log, to the SAS procedure output file, or to an external file that is specified in the most recent FILE statement. Example: data _null_; set redsox; file ‘p:redsox.csv' delimiter=',' dsd; put hr rbi ab hits; run;
  • 29. *The INFILE statement specifies the input file for any INPUT statements in the DATA step. The FILE statement specifies the output file for any PUT statements in the DATA step. *Both the FILE and INFILE statements allow you to use options that provide SAS with additional information about the external file being used. *An INFILE statement usually identifies data from an external file. A DATALINES statement indicates that data follow in the job stream. You can use the INFILE statement with the file specification DATALINES to take advantage of certain data- reading options that effect how the INPUT statement reads in-stream data.
  • 30. *Missing values in SAS are shown by . *As a general rule, SAS procedures that perform computations handle missing data by omitting the missing values, including proc means, proc freq, proc corr, and proc reg *Check SAS web page for more information
  • 31. * SAS treats a missing value as the smallest possible value (e.g., negative infinity) in logical statements. data times6; set times ; if (var1 <= 1.5) then varc1 = 0; else varc1 = 1 ; run ; Output: Obs id var1 varc1 1 1 1.5 0 2 2 . 0 3 3 2.1 1
  • 32. *proc print and proc contents- we have seen these *proc sort *proc means *proc univariate *proc plot
  • 33. *var: lists the variables you want to perform the proc on *by: breaks the data into groups *where: limits the data set to a specific group of observations *output: allows you to output the results into a data set
  • 34. *We can use proc sort to sort data *The code to complete this is proc sort data=extratreat ; by gender ; run ; proc sort data=extratreat out=extreat ; by gender ; run ; proc sort data=extratreat out=extreat2; by descending gender ; run ; proc sort data=extratreat out=extreat3 noduplicates; by gender ; run ;
  • 35. *The basic form of proc means is *proc means data=extratreat; var ______; by _______; where _______; output out=stat mean=bpamean cholamean; run; *The basic form of proc univariate is the same, but much more information is given *It is helpful to use the output window to get the info you need
  • 36. *To make different plots in SAS, you use proc plot *Scatterplot *proc plot data=redsox; plot rbi*ab; run; *You can also make plots using *proc univariate data=redsox plot; var rbi; run;
  • 37. *Find the mean blood pressure on treatment A in women *Make a scatterplot of blood pressure on treatment B versus blood pressure on treatment A in men *Find the median number of home runs hit by the Red Sox
  • 38. Macros are the SAS method of making functions *Avoid repetitious SAS code *Create generalizable and flexible SAS code *Pass information from one part of a SAS job to another *Conditionally execute data steps and PROCs
  • 39. *SAS macro variable *SAS Macro *There are many discussions of macro variables on the web; one good one is given here: http://www2.sas.com/proceedings/sugi30/130 -30.pdf
  • 40. Two delimiters will trigger the macro processor in a SAS program. *&macro-variable This refers to a macro variable. The current value of the variable will replace &macro-variable; *%macro-name This refers to a macro, which consists of one or more complete SAS statements, or even whole data or proc steps.
  • 41. *SAS Macro variables can be defined and used anywhere in a SAS program, except in data lines. They are independent of a SAS dataset.
  • 42. %LET: assign text to a macro variable; %LET macrovar = value 1. Macrovar is the name of a global macro variable; 2. Value is macro variable value, which is a character string without quotation or macro expression. %PUT: display macro variable values as text in the SAS log; %put _all_, %put _user_ &macrovar: Substitute the value of a macro variable in a program;
  • 43. *Here is an example of how to use a macro variable: *%let int=treat; proc means data=&int; run; *Now we can rerun the code again simply changing the value of the macro variable, without altering the rest of the code. *%let int=redsox; proc means data=&int; run; *This is extremely helpful when you have a large amount of code you want to reference
  • 44. *Definition: %MACRO macro-name (parm1, parm2,…parmk); Macro definition (&parm1,&parm2,…&parmk) %MEND macro-name; *Application: %macro-name(values of parm1, parm2,…,parmk);
  • 45. Import Excel to SAS Datasets by a Macro %macro excelsas(in, out); proc import out=work.&out datafile=“g:sharedbio271&in" dbms=excel replace; getnames=yes; run; %mend excelsas; % excelsas(practice.xls,test) Use proc print to ensure that you have the data input properly
  • 46. %let int=treat; %let dop=%str(id bpa); %macro happy; data new; set &int; drop &dop; run; proc means data=new; run; %mend happy; %happy