Health Related Quality of Life (HRQoL) in Metastatic
Download
Report
Transcript Health Related Quality of Life (HRQoL) in Metastatic
Jerry Tsai
[email protected]
This presentation and code available at:
clintuition.com/pubs/
1
Efficiently Handle Lists of Items using the
SAS® Macro Language
--Save Time and Reduce Errors
Jerry Tsai
2
Problem Statement
Working with a data set that contains many
variables often requires repeating the same
editing task over and over on those variables.
Problems with having to make repetitive edits:
Increased chance of inconsistency, leading to
errors in syntax or in logic
Increase in time required for task completion
3
Data Set Examples
#1: Laboratory values
Variables: hemoglobin, hematocrit, MCH, MCV, RBC,
platelets, etc.
#2: Survey data
Variables: Question 1, Question 2, Question 3, etc.
4
Desired Solution
Write code addressing these multiple items
with as little unnecessary repetition as
possible– and do it correctly the first time.
5
Process Flow
Write code that addresses one item on the
list and validate that it works as desired.
Extend the validated code to all items on
the list.
6
Method
Edit the validated code for use with a
macro:
Replace the list item with a wildcard character.
With each iteration, this wildcard will be replaced
with a item on the list.
The macro will iterate through the list
using a loop.
7
MACRO %ITERLIST
Two parameters:
LIST
CODE
%iterlist(list=, code=)
8
Setup
Macro variable containing a space-delimited
list, e.g.:
%let mylist = alfa bravo charlie...yankee
zulu;
9
Example #1: Renaming a List of Vars
data new;
set
old
(
rename =
(alfa = alfa_n)
)
;
run;
10
Example #1: Renaming a List of Vars
data new;
set
Replace item with wildcard character, ‘?’
old
(
? = ?_n
rename =
(alfa = alfa_n)
)
;
run;
11
Example #1: Renaming a List of Vars
data new;
set
old
(
rename =
(? = ?_n)
)
;
run;
12
Example #1: Renaming a List of Vars
data new;
set
old
(
rename =
(
? = ?_n
)
)
;
run;
13
Example #1: Renaming a List of Vars
data new;
set
old
(
rename =
(%iterlist(list = &mylist., code = %str(? = ?_n)))
)
;
run;
14
Example #1: Renaming a List of Vars
data new;
set
old
(
rename =
(alfa = alfa_n
beta = beta_n ... zulu = zulu_n
)
)
;
run;
15
Example #2: PROC MEANS statistics
proc means data = old;
var &mylist.;
output out
= oldstats (drop=_type_ _freq_)
n(alfa
)= alfa_nb
mean(alfa
)= alfa_mn
std(alfa
)= alfa_sd
;
run;
16
Example #2: PROC MEANS statistics
proc means data = old;
var &mylist.;
output out
= oldstats (drop=_type_ _freq_)
%iterlist(list = &mylist., code = %str(
n(?)=?_nb))
%iterlist(list = &mylist., code = %str(mean(?)=?_mn))
%iterlist(list = &mylist., code = %str( std(?)=?_sd))
;
run;
17
Example #3: Nested Macro Call
%macro printem(inputds =, variabl =);
proc print data=&inputds.;
var
&variabl.
;
run;
%mend
printem;
%printem(inputds = old, variabl = alfa);
18
Example #3: Nested Macro Call
%iterlist
(
list = &mylist.,
code = %nrstr(
%printem(inputds = old, variabl = ?);
)
);
19
Advantages of %ITERLIST()
Robust approach separates programming
logic from the items being iterated over.
Save programming time by avoiding
needless typing.
By retaining the syntax of validated code,
reduce the likelihood of error.
20
Noteworthy Aspects of %ITERLIST
%DO-%END looping
Macro quoting functions, e.g., %STR(),
%UNQUOTE()
%QSYSFUNC()
TRANWRD()
21
Suggested Reading
Carpenter, Art. Resolving and Using &&var&i Macro
Variables - SUGI 22 Proceedings (1997)
Carpenter, Art. Storing and Using a List of Values in a
Macro Variable - SUGI 30 Proceedings (2005)
Morris, Robert. Text Utility Macros for Manipulating
Lists of Variable Names - SUGI 30 Proceedings (2005)
Clay, Ted. Tight Looping With Macro Arrays - SUGI
31 Proceedings (2006)
22
Jerry Tsai
[email protected]
Questions? Comments?
This presentation and code available at:
clintuition.com/pubs/
23