Uploaded by Lindani Mncwabe

SYMGET

advertisement
4.3 Retrieving Macro Variables in the DATA Step (Self-Study)
4-43
4.3 Retrieving Macro Variables in the DATA Step (Self-Study)
Objectives


Obtain the value of a macro variable during DATA step
execution.
Describe the difference between the SYMGET
function and macro variable references.
70
The SYMGET Function
75
create macro
variables
retrieve macro
variables
word scanning time
%LET
&macvar
execution time
CALL SYMPUTX
SYMGET(macvar)
4-44
Chapter 4 DATA Step and SQL Interfaces
The SYMGET Function
Retrieve a macro variable’s value during DATA step
execution with the SYMGET function.
Symbol Table
Program Data Vector
DATA Step
Variables
SYMGET
76
The SYMGET Function
General form of the SYMGET function:
SYMGET(macro-variable)
macro-variable can be specified as either of the following:
 character literal
 DATA step character expression
A DATA step variable created by the SYMGET function
is a character variable with a length of 200 bytes unless
it has been previously defined.
77
4.3 Retrieving Macro Variables in the DATA Step (Self-Study)
Review
Create a series of macro variables to store customer names.
data _null_;
set orion.customer;
call symputx('name'||left(customer_ID),
customer_name);
run;
Symbol Table
name4
name5
name9
78
James Kvarniq
Sandrina Stephano
Cornelia Krahl
m104d03d
4-45
4-46
Chapter 4 DATA Step and SQL Interfaces
The SYMGET Function
Example: Look up customer names from the symbol table.
data InternetCustomers;
keep order_date customer_ID customer_name;
set orion.order_fact;
if order_type=3;
length Customer_Name $ 20;
Customer_Name=symget('name'||left(customer_ID));
run;
proc print data=InternetCustomers;
var order_date customer_ID customer_name;
title "Internet Customers";
run;
m104d04
79
The SYMGET Function
Partial PROC PRINT Output
Internet Customers
80
Obs
Order_
Date
Customer_ID
1
2
3
4
5
6
7
8
9
10
11
12
02APR2003
18APR2003
01MAY2003
07MAY2003
20JUN2003
20JUN2003
03JUL2003
15JUL2003
15JUL2003
06AUG2003
06AUG2003
20AUG2003
70046
36
171
11171
17023
17023
171
36
36
3959
3959
52
Customer_Name
Tommy Mcdonald
Phenix Hill
Robert Bowerman
Bill Cuddy
Susan Krasowski
Susan Krasowski
Robert Bowerman
Phenix Hill
Phenix Hill
Rita Lotz
Rita Lotz
Yan Kozlowski
Download