SlideShare a Scribd company logo
1 of 20
Derive Value from Excellence…
G -
SAS Macro – Part 1
By- Kavita Dargan
Derive Value from Excellence…
Agenda
Purpose of Macro Facility
Types of macro variables – Automatic vs User defined
Different ways of creating macro variable
Global vs. Local symbol table
Combining macro variable reference with text
Questions?
Derive Value from Excellence…
Purpose of Macro Facility
• Using the macro language, you can write SAS programs that
are dynamic, or capable of self modification.
• Write special programs called macros that generate tailored
SAS code.
• You can create and resolve macro variables anywhere in a SAS
program.
• You can utilize automatic macro variables that contain
information regarding your system environment.
Derive Value from Excellence…
Types of Macro Variables
 Automatic variables
• Created at SAS invocation
• Global (always available)
• Usually assigned by SAS but some
can be by user
• Example- Sysdate, Systime, Sysver,
Sysday etc
• Use %put _automatic_ in program
to view all available automatic
macro variables in log.
 User-defined variables
• Create own macro variable.
• If already exists then replaces the
current value.
• Leading and trailing blanks are
removed before assignment.
• Can be created using %Let, Into
clause, Call symput etc
• Use %put _user_ in program to
view all available user-defined
macro variables in log.
Derive Value from Excellence…
Types of Macro Variables Contd.
 Example: Substitute system information in footnote.
 Output:
footnote1 "Created &systime &sysday, &sysdate9";
footnote2
"on the &sysscp system using Release &sysver";
Derive Value from Excellence…
Different ways of creating macro
variables
 %LET
- Variable can be any name following the SAS naming convention.
- If variable already exists in the symbol table, value replaces the current
value.
- If either variable or value contains a macro trigger (&), it is evaluated
before the assignment is made.
- Rules for value:
• Maximum length is 32 characters and minimum length is 0 characters.
• Numeric tokens are stored as character strings and case is reserved.
• Mathematical expressions not evaluated.
• Quotes are stored as values.
• Leading and trailing blanks are removed before assignment which are not in
quotes.
%LET variable=value;
Derive Value from Excellence…
Different ways of creating macro
variables Contd.
 Examples of %LET statement
%let name= Ed Norton ;
%let name2=’ Ed Norton ’;
%let title="Joan’s Report";
%let start=;
%let total=0;
%let sum=3+4;
%let total=&total+∑
%let x=varlist;
%let &x=name age height;
Value
Ed Norton
’ Ed Norton ’
“Joan’s Report”
0
3+4
varlist
name age height
Derive Value from Excellence…
Different ways of creating macro
variables Contd.
 SYMPUT Routine using Literal
- First argument specify name for the macro variable
- Second argument specify the character value to be assigned to the
macro variable.
- If macro-variable already exists, the value of the text replaces the old
value.
CALL SYMPUT('macro-variable', 'text');
Derive Value from Excellence…
Different ways of creating macro
variables Contd.
 SYMPUT Routine using Data-step-variable
- Current value stored in data-step-variable to be assigned to the macro
variable.
- If macro-variable already exists, the value of the data-step-variable
replaces the old value.
- Maximum of 32767 characters can be assigned to the receiving macro
variable.
- Any leading or trailing blanks stored in value are assigned to macro
variable.
CALL SYMPUT(‘macro-variable’, Data-step-variable);
Derive Value from Excellence…
Different ways of creating macro
variables Contd.
 SYMPUT Routine using Data-step-expression
- Value of the expression to be assigned to the macro variable.
- If macro-variable already exists, the value of the expression replaces the
old value.
- Maximum 32767 characters can be assigned to the receiving macro
variable.
- Numeric expression are automatically converted to character using
BEST12. format.
- One can remove leading and trailing blanks in a variable by this method.
CALL SYMPUT(‘macro-variable’, expression);
Derive Value from Excellence…
Different ways of creating macro
variables Contd.
 SYMPUT Routine to create multiple macro variables
- Expression1 evaluates to a character value that is a valid macro variable
name. This value should change each time you want to create another
macro variable.
- Expression2 is the value you want to assign to a specific macro variable.
- This way, we can create multiple macro variables in one data step.
- Advantage
• Efficiency
• Reduced coding
CALL SYMPUT(expression1, expression2);
Derive Value from Excellence…
Different ways of creating macro
variables Contd.
 Example
data _null_;
set courses;
call symput(course_code,trim(course_title));
run;
%put _user_;
Note: There are 6 observations in dataset courses.
Derive Value from Excellence…
Different ways of creating macro
variables Contd.
 INTO Clause
- One can specify one or more macro variables to create.
- Create new macro variables per row in the result of select statement.
- This method does not trim leading or trailing blanks.
SELECT col1, col2,. . . INTO :mvar1 - :mvarn,
:nvar1 - :nvarn,...
FROM table-expression
WHERE where-expression
other clauses;
Derive Value from Excellence…
Different ways of creating macro
variables Contd.
 INTO Clause example
- Create ranges of macro variables that contain the course code, location,
and starting date of the first two courses scheduled in 2002.
proc sql noprint;
select course_code,location,
begin_date format=mmddyy10.
into :crsid1-:crsid2,
:place1-:place2,
:date1-:date2
from schedule
where year(begin_date)=2002
order by begin_date;
quit;
SQL Result
Derive Value from Excellence…
Different ways of creating macro
variables Contd.
 Another form of INTO Clause
- It takes the values of a column and concatenates them into one macro
variable, there by creating delimited list of values. Example,
SELECT col1, . . .
INTO :mvar SEPARATED BY ’delimiter’,...
FROM table-expression
WHERE where-expression
other clauses;
proc sql noprint;
select distinct location into :sites
separated by ‘ ‘ from schedule;
quit;
Result: Macro variable sites resolves to Boston Dollas Seattle
Derive Value from Excellence…
Global symbol table vs. Local symbol table
 Macro defined by %global, variable
is held in global symbol table.
Whenever the SAS System is
invoked, a global symbol table is
created and initialized with
automatic or system-defined macro
variables.
 You can create user-defined global
macro variables with the %LET, Call
SYMPUT, INTO clause statement if it
is defined outside a macro definition
(called open code).
 Macro defined by %local, variable
is held in local symbol table.
Whenever a macro variable is
defined within a macro and is not
defined as global, variable is held in
local symbol table and it exists only
during execution of the macro in
which it is defined.
Variables declared in a parameter
list on a macro call are always
stored in a local symbol table.
Note: When you define macro with no arguments, local symbol table is not created and all the variables
defined inside the macro will be global and can be accessible inside as well as outside the macro.
Derive Value from Excellence…
Global vs. Local symbol table Contd.
 Example
%let x=0;
%macro outer;
%local x;
%let x=1;
%inner;
%mend outer;
%macro inner;
%local y;
%let y=&x;
%mend local;
Derive Value from Excellence…
Combining macro variable with text
 In general, macro variable reference is made by preceding the macro
variable name with an ampersand (&).
 Referencing a nonexistent macro variable results in a warning message.
WARNING: Apparent symbolic reference xxxxx not
resolved.
 Macro variable can be reference adjacent to leading and/or trailing text.
i.e. text&variable, &variable.text, text&variable.text
 Macro variable can be refence adjacent to another macro variable
reference. i.e. &variable1&variable2
Derive Value from Excellence…
Combining macro variable with text
 Example
%let lib=perm; %let year=90;
Libname &lib ‘SAS data library’;
Proc &graphics.chart
data=&lib..y&year&month;
Plot &var*day;
Run;
%let graphics=g; %let month=jan; %let var=sale;
Libname perm ‘SAS data library’;
Proc gchart data=perm.y90jan;
Plot sale*day;
Run;
Derive Value from Excellence…
Questions

More Related Content

What's hot

SAS Macros part 4.1
SAS Macros part 4.1SAS Macros part 4.1
SAS Macros part 4.1venkatam
 
SAS Macros part 3
SAS Macros part 3SAS Macros part 3
SAS Macros part 3venkatam
 
A Step-By-Step Introduction to SAS Report Procedure
A Step-By-Step Introduction to SAS Report ProcedureA Step-By-Step Introduction to SAS Report Procedure
A Step-By-Step Introduction to SAS Report ProcedureYesAnalytics
 
Base sas interview questions
Base sas interview questionsBase sas interview questions
Base sas interview questionsDr P Deepak
 
Proc SQL in SAS Enterprise Guide 4.3
Proc SQL in SAS Enterprise Guide 4.3Proc SQL in SAS Enterprise Guide 4.3
Proc SQL in SAS Enterprise Guide 4.3Mark Tabladillo
 
Conditional statements in sas
Conditional statements in sasConditional statements in sas
Conditional statements in sasvenkatam
 
SAS Macros part 2
SAS Macros part 2SAS Macros part 2
SAS Macros part 2venkatam
 
SAS Access / SAS Connect
SAS Access / SAS ConnectSAS Access / SAS Connect
SAS Access / SAS Connectguest2160992
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Beat Signer
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In SqlAnurag
 
Introduction To Sas
Introduction To SasIntroduction To Sas
Introduction To Sashalasti
 
Understanding SAS Data Step Processing
Understanding SAS Data Step ProcessingUnderstanding SAS Data Step Processing
Understanding SAS Data Step Processingguest2160992
 
SAS cheat sheet
SAS cheat sheetSAS cheat sheet
SAS cheat sheetAli Ajouz
 

What's hot (20)

SAS Macros part 4.1
SAS Macros part 4.1SAS Macros part 4.1
SAS Macros part 4.1
 
Sas cheat
Sas cheatSas cheat
Sas cheat
 
SAS Proc SQL
SAS Proc SQLSAS Proc SQL
SAS Proc SQL
 
Sas array statement
Sas array statementSas array statement
Sas array statement
 
SAS Macros part 3
SAS Macros part 3SAS Macros part 3
SAS Macros part 3
 
Sas Plots Graphs
Sas Plots GraphsSas Plots Graphs
Sas Plots Graphs
 
A Step-By-Step Introduction to SAS Report Procedure
A Step-By-Step Introduction to SAS Report ProcedureA Step-By-Step Introduction to SAS Report Procedure
A Step-By-Step Introduction to SAS Report Procedure
 
Base sas interview questions
Base sas interview questionsBase sas interview questions
Base sas interview questions
 
Proc SQL in SAS Enterprise Guide 4.3
Proc SQL in SAS Enterprise Guide 4.3Proc SQL in SAS Enterprise Guide 4.3
Proc SQL in SAS Enterprise Guide 4.3
 
Conditional statements in sas
Conditional statements in sasConditional statements in sas
Conditional statements in sas
 
SAS Macros part 2
SAS Macros part 2SAS Macros part 2
SAS Macros part 2
 
SAS Access / SAS Connect
SAS Access / SAS ConnectSAS Access / SAS Connect
SAS Access / SAS Connect
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
 
Arrays in SAS
Arrays in SASArrays in SAS
Arrays in SAS
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
Introduction To Sas
Introduction To SasIntroduction To Sas
Introduction To Sas
 
SAS Internal Training
SAS Internal TrainingSAS Internal Training
SAS Internal Training
 
Understanding SAS Data Step Processing
Understanding SAS Data Step ProcessingUnderstanding SAS Data Step Processing
Understanding SAS Data Step Processing
 
Sql
SqlSql
Sql
 
SAS cheat sheet
SAS cheat sheetSAS cheat sheet
SAS cheat sheet
 

Similar to SAS Macro

BAS 150 Lesson 8 Lecture
BAS 150 Lesson 8 LectureBAS 150 Lesson 8 Lecture
BAS 150 Lesson 8 LectureWake Tech BAS
 
Task Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdfTask Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdfacsmadurai
 
Inline functions & macros
Inline functions & macrosInline functions & macros
Inline functions & macrosAnand Kumar
 
Getting started with CATIA V5 Macros
Getting started with CATIA V5 MacrosGetting started with CATIA V5 Macros
Getting started with CATIA V5 MacrosEmmett Ross
 
Sas macros part 4.1
Sas macros part 4.1Sas macros part 4.1
Sas macros part 4.1venkatam
 
E learning excel vba programming lesson 3
E learning excel vba programming  lesson 3E learning excel vba programming  lesson 3
E learning excel vba programming lesson 3Vijay Perepa
 
Intro to tsql unit 13
Intro to tsql   unit 13Intro to tsql   unit 13
Intro to tsql unit 13Syed Asrarali
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationAkhil Kaushik
 
Robust and declarative machine learning pipelines for predictive buying at Ba...
Robust and declarative machine learning pipelines for predictive buying at Ba...Robust and declarative machine learning pipelines for predictive buying at Ba...
Robust and declarative machine learning pipelines for predictive buying at Ba...Gianmario Spacagna
 
Vba and macro creation (using excel)
Vba and macro creation (using excel)Vba and macro creation (using excel)
Vba and macro creation (using excel)Javier Morales Cauna
 
Power of call symput data
Power of call symput dataPower of call symput data
Power of call symput dataYash Sharma
 
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxINTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxDeepasCSE
 
Intro to tsql unit 11
Intro to tsql   unit 11Intro to tsql   unit 11
Intro to tsql unit 11Syed Asrarali
 

Similar to SAS Macro (20)

BAS 150 Lesson 8 Lecture
BAS 150 Lesson 8 LectureBAS 150 Lesson 8 Lecture
BAS 150 Lesson 8 Lecture
 
Ss4
Ss4Ss4
Ss4
 
Task Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdfTask Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdf
 
Module 5.pdf
Module 5.pdfModule 5.pdf
Module 5.pdf
 
Unit 2
Unit 2Unit 2
Unit 2
 
Macro-processor
Macro-processorMacro-processor
Macro-processor
 
Inline functions & macros
Inline functions & macrosInline functions & macros
Inline functions & macros
 
Getting started with CATIA V5 Macros
Getting started with CATIA V5 MacrosGetting started with CATIA V5 Macros
Getting started with CATIA V5 Macros
 
handout6.pdf
handout6.pdfhandout6.pdf
handout6.pdf
 
Sas macros part 4.1
Sas macros part 4.1Sas macros part 4.1
Sas macros part 4.1
 
E learning excel vba programming lesson 3
E learning excel vba programming  lesson 3E learning excel vba programming  lesson 3
E learning excel vba programming lesson 3
 
Intro to tsql unit 13
Intro to tsql   unit 13Intro to tsql   unit 13
Intro to tsql unit 13
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
 
Unit 4 sp macro
Unit 4 sp macroUnit 4 sp macro
Unit 4 sp macro
 
VBA
VBAVBA
VBA
 
Robust and declarative machine learning pipelines for predictive buying at Ba...
Robust and declarative machine learning pipelines for predictive buying at Ba...Robust and declarative machine learning pipelines for predictive buying at Ba...
Robust and declarative machine learning pipelines for predictive buying at Ba...
 
Vba and macro creation (using excel)
Vba and macro creation (using excel)Vba and macro creation (using excel)
Vba and macro creation (using excel)
 
Power of call symput data
Power of call symput dataPower of call symput data
Power of call symput data
 
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxINTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
 
Intro to tsql unit 11
Intro to tsql   unit 11Intro to tsql   unit 11
Intro to tsql unit 11
 

Recently uploaded

Russian Call Girls in Chandigarh Ojaswi ❤️🍑 9907093804 👄🫦 Independent Escort ...
Russian Call Girls in Chandigarh Ojaswi ❤️🍑 9907093804 👄🫦 Independent Escort ...Russian Call Girls in Chandigarh Ojaswi ❤️🍑 9907093804 👄🫦 Independent Escort ...
Russian Call Girls in Chandigarh Ojaswi ❤️🍑 9907093804 👄🫦 Independent Escort ...High Profile Call Girls Chandigarh Aarushi
 
Low Rate Call Girls In Bommanahalli Just Call 7001305949
Low Rate Call Girls In Bommanahalli Just Call 7001305949Low Rate Call Girls In Bommanahalli Just Call 7001305949
Low Rate Call Girls In Bommanahalli Just Call 7001305949ps5894268
 
Russian Escorts Aishbagh Road * 9548273370 Naughty Call Girls Service in Lucknow
Russian Escorts Aishbagh Road * 9548273370 Naughty Call Girls Service in LucknowRussian Escorts Aishbagh Road * 9548273370 Naughty Call Girls Service in Lucknow
Russian Escorts Aishbagh Road * 9548273370 Naughty Call Girls Service in Lucknowgragteena
 
Call Girl Chandigarh Mallika ❤️🍑 9907093804 👄🫦 Independent Escort Service Cha...
Call Girl Chandigarh Mallika ❤️🍑 9907093804 👄🫦 Independent Escort Service Cha...Call Girl Chandigarh Mallika ❤️🍑 9907093804 👄🫦 Independent Escort Service Cha...
Call Girl Chandigarh Mallika ❤️🍑 9907093804 👄🫦 Independent Escort Service Cha...High Profile Call Girls Chandigarh Aarushi
 
College Call Girls Hyderabad Sakshi 9907093804 Independent Escort Service Hyd...
College Call Girls Hyderabad Sakshi 9907093804 Independent Escort Service Hyd...College Call Girls Hyderabad Sakshi 9907093804 Independent Escort Service Hyd...
College Call Girls Hyderabad Sakshi 9907093804 Independent Escort Service Hyd...delhimodelshub1
 
Russian Escorts Delhi | 9711199171 | all area service available
Russian Escorts Delhi | 9711199171 | all area service availableRussian Escorts Delhi | 9711199171 | all area service available
Russian Escorts Delhi | 9711199171 | all area service availablesandeepkumar69420
 
Call Girls in Hyderabad Lavanya 9907093804 Independent Escort Service Hyderabad
Call Girls in Hyderabad Lavanya 9907093804 Independent Escort Service HyderabadCall Girls in Hyderabad Lavanya 9907093804 Independent Escort Service Hyderabad
Call Girls in Hyderabad Lavanya 9907093804 Independent Escort Service Hyderabaddelhimodelshub1
 
Russian Call Girls in Raipur 9873940964 Book Hot And Sexy Girls
Russian Call Girls in Raipur 9873940964 Book Hot And Sexy GirlsRussian Call Girls in Raipur 9873940964 Book Hot And Sexy Girls
Russian Call Girls in Raipur 9873940964 Book Hot And Sexy Girlsddev2574
 
VIP Call Girls Sector 67 Gurgaon Just Call Me 9711199012
VIP Call Girls Sector 67 Gurgaon Just Call Me 9711199012VIP Call Girls Sector 67 Gurgaon Just Call Me 9711199012
VIP Call Girls Sector 67 Gurgaon Just Call Me 9711199012Call Girls Service Gurgaon
 
Leading transformational change: inner and outer skills
Leading transformational change: inner and outer skillsLeading transformational change: inner and outer skills
Leading transformational change: inner and outer skillsHelenBevan4
 
Call Girl Hyderabad Madhuri 9907093804 Independent Escort Service Hyderabad
Call Girl Hyderabad Madhuri 9907093804 Independent Escort Service HyderabadCall Girl Hyderabad Madhuri 9907093804 Independent Escort Service Hyderabad
Call Girl Hyderabad Madhuri 9907093804 Independent Escort Service Hyderabaddelhimodelshub1
 
Call Girls Hyderabad Kirti 9907093804 Independent Escort Service Hyderabad
Call Girls Hyderabad Kirti 9907093804 Independent Escort Service HyderabadCall Girls Hyderabad Kirti 9907093804 Independent Escort Service Hyderabad
Call Girls Hyderabad Kirti 9907093804 Independent Escort Service Hyderabaddelhimodelshub1
 
Russian Call Girls Hyderabad Indira 9907093804 Independent Escort Service Hyd...
Russian Call Girls Hyderabad Indira 9907093804 Independent Escort Service Hyd...Russian Call Girls Hyderabad Indira 9907093804 Independent Escort Service Hyd...
Russian Call Girls Hyderabad Indira 9907093804 Independent Escort Service Hyd...delhimodelshub1
 
Dehradun Call Girls Service ❤️🍑 9675010100 👄🫦Independent Escort Service Dehradun
Dehradun Call Girls Service ❤️🍑 9675010100 👄🫦Independent Escort Service DehradunDehradun Call Girls Service ❤️🍑 9675010100 👄🫦Independent Escort Service Dehradun
Dehradun Call Girls Service ❤️🍑 9675010100 👄🫦Independent Escort Service DehradunNiamh verma
 
Kukatpally Call Girls Services 9907093804 High Class Babes Here Call Now
Kukatpally Call Girls Services 9907093804 High Class Babes Here Call NowKukatpally Call Girls Services 9907093804 High Class Babes Here Call Now
Kukatpally Call Girls Services 9907093804 High Class Babes Here Call NowHyderabad Call Girls Services
 
Call Girls in Mohali Surbhi ❤️🍑 9907093804 👄🫦 Independent Escort Service Mohali
Call Girls in Mohali Surbhi ❤️🍑 9907093804 👄🫦 Independent Escort Service MohaliCall Girls in Mohali Surbhi ❤️🍑 9907093804 👄🫦 Independent Escort Service Mohali
Call Girls in Mohali Surbhi ❤️🍑 9907093804 👄🫦 Independent Escort Service MohaliHigh Profile Call Girls Chandigarh Aarushi
 
Call Girls LB Nagar 7001305949 all area service COD available Any Time
Call Girls LB Nagar 7001305949 all area service COD available Any TimeCall Girls LB Nagar 7001305949 all area service COD available Any Time
Call Girls LB Nagar 7001305949 all area service COD available Any Timedelhimodelshub1
 
Call Girl Gurgaon Saloni 9711199012 Independent Escort Service Gurgaon
Call Girl Gurgaon Saloni 9711199012 Independent Escort Service GurgaonCall Girl Gurgaon Saloni 9711199012 Independent Escort Service Gurgaon
Call Girl Gurgaon Saloni 9711199012 Independent Escort Service GurgaonCall Girls Service Gurgaon
 

Recently uploaded (20)

Russian Call Girls in Chandigarh Ojaswi ❤️🍑 9907093804 👄🫦 Independent Escort ...
Russian Call Girls in Chandigarh Ojaswi ❤️🍑 9907093804 👄🫦 Independent Escort ...Russian Call Girls in Chandigarh Ojaswi ❤️🍑 9907093804 👄🫦 Independent Escort ...
Russian Call Girls in Chandigarh Ojaswi ❤️🍑 9907093804 👄🫦 Independent Escort ...
 
Low Rate Call Girls In Bommanahalli Just Call 7001305949
Low Rate Call Girls In Bommanahalli Just Call 7001305949Low Rate Call Girls In Bommanahalli Just Call 7001305949
Low Rate Call Girls In Bommanahalli Just Call 7001305949
 
Russian Escorts Aishbagh Road * 9548273370 Naughty Call Girls Service in Lucknow
Russian Escorts Aishbagh Road * 9548273370 Naughty Call Girls Service in LucknowRussian Escorts Aishbagh Road * 9548273370 Naughty Call Girls Service in Lucknow
Russian Escorts Aishbagh Road * 9548273370 Naughty Call Girls Service in Lucknow
 
Call Girl Chandigarh Mallika ❤️🍑 9907093804 👄🫦 Independent Escort Service Cha...
Call Girl Chandigarh Mallika ❤️🍑 9907093804 👄🫦 Independent Escort Service Cha...Call Girl Chandigarh Mallika ❤️🍑 9907093804 👄🫦 Independent Escort Service Cha...
Call Girl Chandigarh Mallika ❤️🍑 9907093804 👄🫦 Independent Escort Service Cha...
 
College Call Girls Hyderabad Sakshi 9907093804 Independent Escort Service Hyd...
College Call Girls Hyderabad Sakshi 9907093804 Independent Escort Service Hyd...College Call Girls Hyderabad Sakshi 9907093804 Independent Escort Service Hyd...
College Call Girls Hyderabad Sakshi 9907093804 Independent Escort Service Hyd...
 
Russian Escorts Delhi | 9711199171 | all area service available
Russian Escorts Delhi | 9711199171 | all area service availableRussian Escorts Delhi | 9711199171 | all area service available
Russian Escorts Delhi | 9711199171 | all area service available
 
Call Girls in Lucknow Esha 🔝 8923113531 🔝 🎶 Independent Escort Service Lucknow
Call Girls in Lucknow Esha 🔝 8923113531  🔝 🎶 Independent Escort Service LucknowCall Girls in Lucknow Esha 🔝 8923113531  🔝 🎶 Independent Escort Service Lucknow
Call Girls in Lucknow Esha 🔝 8923113531 🔝 🎶 Independent Escort Service Lucknow
 
Call Girls in Hyderabad Lavanya 9907093804 Independent Escort Service Hyderabad
Call Girls in Hyderabad Lavanya 9907093804 Independent Escort Service HyderabadCall Girls in Hyderabad Lavanya 9907093804 Independent Escort Service Hyderabad
Call Girls in Hyderabad Lavanya 9907093804 Independent Escort Service Hyderabad
 
Russian Call Girls in Raipur 9873940964 Book Hot And Sexy Girls
Russian Call Girls in Raipur 9873940964 Book Hot And Sexy GirlsRussian Call Girls in Raipur 9873940964 Book Hot And Sexy Girls
Russian Call Girls in Raipur 9873940964 Book Hot And Sexy Girls
 
VIP Call Girls Sector 67 Gurgaon Just Call Me 9711199012
VIP Call Girls Sector 67 Gurgaon Just Call Me 9711199012VIP Call Girls Sector 67 Gurgaon Just Call Me 9711199012
VIP Call Girls Sector 67 Gurgaon Just Call Me 9711199012
 
Leading transformational change: inner and outer skills
Leading transformational change: inner and outer skillsLeading transformational change: inner and outer skills
Leading transformational change: inner and outer skills
 
Call Girl Hyderabad Madhuri 9907093804 Independent Escort Service Hyderabad
Call Girl Hyderabad Madhuri 9907093804 Independent Escort Service HyderabadCall Girl Hyderabad Madhuri 9907093804 Independent Escort Service Hyderabad
Call Girl Hyderabad Madhuri 9907093804 Independent Escort Service Hyderabad
 
Call Girls Hyderabad Kirti 9907093804 Independent Escort Service Hyderabad
Call Girls Hyderabad Kirti 9907093804 Independent Escort Service HyderabadCall Girls Hyderabad Kirti 9907093804 Independent Escort Service Hyderabad
Call Girls Hyderabad Kirti 9907093804 Independent Escort Service Hyderabad
 
Russian Call Girls Hyderabad Indira 9907093804 Independent Escort Service Hyd...
Russian Call Girls Hyderabad Indira 9907093804 Independent Escort Service Hyd...Russian Call Girls Hyderabad Indira 9907093804 Independent Escort Service Hyd...
Russian Call Girls Hyderabad Indira 9907093804 Independent Escort Service Hyd...
 
Dehradun Call Girls Service ❤️🍑 9675010100 👄🫦Independent Escort Service Dehradun
Dehradun Call Girls Service ❤️🍑 9675010100 👄🫦Independent Escort Service DehradunDehradun Call Girls Service ❤️🍑 9675010100 👄🫦Independent Escort Service Dehradun
Dehradun Call Girls Service ❤️🍑 9675010100 👄🫦Independent Escort Service Dehradun
 
Kukatpally Call Girls Services 9907093804 High Class Babes Here Call Now
Kukatpally Call Girls Services 9907093804 High Class Babes Here Call NowKukatpally Call Girls Services 9907093804 High Class Babes Here Call Now
Kukatpally Call Girls Services 9907093804 High Class Babes Here Call Now
 
College Call Girls Dehradun Kavya 🔝 7001305949 🔝 📍 Independent Escort Service...
College Call Girls Dehradun Kavya 🔝 7001305949 🔝 📍 Independent Escort Service...College Call Girls Dehradun Kavya 🔝 7001305949 🔝 📍 Independent Escort Service...
College Call Girls Dehradun Kavya 🔝 7001305949 🔝 📍 Independent Escort Service...
 
Call Girls in Mohali Surbhi ❤️🍑 9907093804 👄🫦 Independent Escort Service Mohali
Call Girls in Mohali Surbhi ❤️🍑 9907093804 👄🫦 Independent Escort Service MohaliCall Girls in Mohali Surbhi ❤️🍑 9907093804 👄🫦 Independent Escort Service Mohali
Call Girls in Mohali Surbhi ❤️🍑 9907093804 👄🫦 Independent Escort Service Mohali
 
Call Girls LB Nagar 7001305949 all area service COD available Any Time
Call Girls LB Nagar 7001305949 all area service COD available Any TimeCall Girls LB Nagar 7001305949 all area service COD available Any Time
Call Girls LB Nagar 7001305949 all area service COD available Any Time
 
Call Girl Gurgaon Saloni 9711199012 Independent Escort Service Gurgaon
Call Girl Gurgaon Saloni 9711199012 Independent Escort Service GurgaonCall Girl Gurgaon Saloni 9711199012 Independent Escort Service Gurgaon
Call Girl Gurgaon Saloni 9711199012 Independent Escort Service Gurgaon
 

SAS Macro

  • 1. Derive Value from Excellence… G - SAS Macro – Part 1 By- Kavita Dargan
  • 2. Derive Value from Excellence… Agenda Purpose of Macro Facility Types of macro variables – Automatic vs User defined Different ways of creating macro variable Global vs. Local symbol table Combining macro variable reference with text Questions?
  • 3. Derive Value from Excellence… Purpose of Macro Facility • Using the macro language, you can write SAS programs that are dynamic, or capable of self modification. • Write special programs called macros that generate tailored SAS code. • You can create and resolve macro variables anywhere in a SAS program. • You can utilize automatic macro variables that contain information regarding your system environment.
  • 4. Derive Value from Excellence… Types of Macro Variables  Automatic variables • Created at SAS invocation • Global (always available) • Usually assigned by SAS but some can be by user • Example- Sysdate, Systime, Sysver, Sysday etc • Use %put _automatic_ in program to view all available automatic macro variables in log.  User-defined variables • Create own macro variable. • If already exists then replaces the current value. • Leading and trailing blanks are removed before assignment. • Can be created using %Let, Into clause, Call symput etc • Use %put _user_ in program to view all available user-defined macro variables in log.
  • 5. Derive Value from Excellence… Types of Macro Variables Contd.  Example: Substitute system information in footnote.  Output: footnote1 "Created &systime &sysday, &sysdate9"; footnote2 "on the &sysscp system using Release &sysver";
  • 6. Derive Value from Excellence… Different ways of creating macro variables  %LET - Variable can be any name following the SAS naming convention. - If variable already exists in the symbol table, value replaces the current value. - If either variable or value contains a macro trigger (&), it is evaluated before the assignment is made. - Rules for value: • Maximum length is 32 characters and minimum length is 0 characters. • Numeric tokens are stored as character strings and case is reserved. • Mathematical expressions not evaluated. • Quotes are stored as values. • Leading and trailing blanks are removed before assignment which are not in quotes. %LET variable=value;
  • 7. Derive Value from Excellence… Different ways of creating macro variables Contd.  Examples of %LET statement %let name= Ed Norton ; %let name2=’ Ed Norton ’; %let title="Joan’s Report"; %let start=; %let total=0; %let sum=3+4; %let total=&total+∑ %let x=varlist; %let &x=name age height; Value Ed Norton ’ Ed Norton ’ “Joan’s Report” 0 3+4 varlist name age height
  • 8. Derive Value from Excellence… Different ways of creating macro variables Contd.  SYMPUT Routine using Literal - First argument specify name for the macro variable - Second argument specify the character value to be assigned to the macro variable. - If macro-variable already exists, the value of the text replaces the old value. CALL SYMPUT('macro-variable', 'text');
  • 9. Derive Value from Excellence… Different ways of creating macro variables Contd.  SYMPUT Routine using Data-step-variable - Current value stored in data-step-variable to be assigned to the macro variable. - If macro-variable already exists, the value of the data-step-variable replaces the old value. - Maximum of 32767 characters can be assigned to the receiving macro variable. - Any leading or trailing blanks stored in value are assigned to macro variable. CALL SYMPUT(‘macro-variable’, Data-step-variable);
  • 10. Derive Value from Excellence… Different ways of creating macro variables Contd.  SYMPUT Routine using Data-step-expression - Value of the expression to be assigned to the macro variable. - If macro-variable already exists, the value of the expression replaces the old value. - Maximum 32767 characters can be assigned to the receiving macro variable. - Numeric expression are automatically converted to character using BEST12. format. - One can remove leading and trailing blanks in a variable by this method. CALL SYMPUT(‘macro-variable’, expression);
  • 11. Derive Value from Excellence… Different ways of creating macro variables Contd.  SYMPUT Routine to create multiple macro variables - Expression1 evaluates to a character value that is a valid macro variable name. This value should change each time you want to create another macro variable. - Expression2 is the value you want to assign to a specific macro variable. - This way, we can create multiple macro variables in one data step. - Advantage • Efficiency • Reduced coding CALL SYMPUT(expression1, expression2);
  • 12. Derive Value from Excellence… Different ways of creating macro variables Contd.  Example data _null_; set courses; call symput(course_code,trim(course_title)); run; %put _user_; Note: There are 6 observations in dataset courses.
  • 13. Derive Value from Excellence… Different ways of creating macro variables Contd.  INTO Clause - One can specify one or more macro variables to create. - Create new macro variables per row in the result of select statement. - This method does not trim leading or trailing blanks. SELECT col1, col2,. . . INTO :mvar1 - :mvarn, :nvar1 - :nvarn,... FROM table-expression WHERE where-expression other clauses;
  • 14. Derive Value from Excellence… Different ways of creating macro variables Contd.  INTO Clause example - Create ranges of macro variables that contain the course code, location, and starting date of the first two courses scheduled in 2002. proc sql noprint; select course_code,location, begin_date format=mmddyy10. into :crsid1-:crsid2, :place1-:place2, :date1-:date2 from schedule where year(begin_date)=2002 order by begin_date; quit; SQL Result
  • 15. Derive Value from Excellence… Different ways of creating macro variables Contd.  Another form of INTO Clause - It takes the values of a column and concatenates them into one macro variable, there by creating delimited list of values. Example, SELECT col1, . . . INTO :mvar SEPARATED BY ’delimiter’,... FROM table-expression WHERE where-expression other clauses; proc sql noprint; select distinct location into :sites separated by ‘ ‘ from schedule; quit; Result: Macro variable sites resolves to Boston Dollas Seattle
  • 16. Derive Value from Excellence… Global symbol table vs. Local symbol table  Macro defined by %global, variable is held in global symbol table. Whenever the SAS System is invoked, a global symbol table is created and initialized with automatic or system-defined macro variables.  You can create user-defined global macro variables with the %LET, Call SYMPUT, INTO clause statement if it is defined outside a macro definition (called open code).  Macro defined by %local, variable is held in local symbol table. Whenever a macro variable is defined within a macro and is not defined as global, variable is held in local symbol table and it exists only during execution of the macro in which it is defined. Variables declared in a parameter list on a macro call are always stored in a local symbol table. Note: When you define macro with no arguments, local symbol table is not created and all the variables defined inside the macro will be global and can be accessible inside as well as outside the macro.
  • 17. Derive Value from Excellence… Global vs. Local symbol table Contd.  Example %let x=0; %macro outer; %local x; %let x=1; %inner; %mend outer; %macro inner; %local y; %let y=&x; %mend local;
  • 18. Derive Value from Excellence… Combining macro variable with text  In general, macro variable reference is made by preceding the macro variable name with an ampersand (&).  Referencing a nonexistent macro variable results in a warning message. WARNING: Apparent symbolic reference xxxxx not resolved.  Macro variable can be reference adjacent to leading and/or trailing text. i.e. text&variable, &variable.text, text&variable.text  Macro variable can be refence adjacent to another macro variable reference. i.e. &variable1&variable2
  • 19. Derive Value from Excellence… Combining macro variable with text  Example %let lib=perm; %let year=90; Libname &lib ‘SAS data library’; Proc &graphics.chart data=&lib..y&year&month; Plot &var*day; Run; %let graphics=g; %let month=jan; %let var=sale; Libname perm ‘SAS data library’; Proc gchart data=perm.y90jan; Plot sale*day; Run;
  • 20. Derive Value from Excellence… Questions