我有一个长长的属性列表,用于我的 SAS 代码中的多个数据集,但我不知道如何创建一个宏变量,该变量将允许我避免重新输入这个长长的属性列表,只有宏变量允许我做一些事情,比如重复 sysUser 或日期。我的属性列表在下面的代码中:
attrib
Subj label = "Subject Number"
sfReas label = "Screen Failure Reason" length = $ 50
sfStatus label = "Screen Failure Status (0 = Failed)" length = $ 1
BioSex label = "Biological Sex" length = $ 1
VisitDate label = "Visit Date" length = $ 10
failDate label = "Failure Notification Date" length = $ 10
sbp label = "Systolic Blood Pressure"
dbp label = "Diastolic Blood Pressure"
bpUnits label = "Units (BP)" length = $ 5
pulse label = "Pulse"
pulseUnits label = "Units (Pulse)" length = $ 9
position label = "Position" length = $ 9
temp label = "Temperature" format = 5.1
tempUnits label = "Units (Temp)" length = $ 1
weight label = "Weight"
weightUnits label = "Units (Weight)" length = $ 2
pain label = "Pain Score";
谁能告诉我如何创建一个宏变量来编码所有这些?
因为您似乎想将单个语句的一部分存储到宏变量中,这应该很容易。
%let common=
Subj label = "Subject Number"
sfReas label = "Screen Failure Reason" length = $ 50
sfStatus label = "Screen Failure Status (0 = Failed)" length = $ 1
BioSex label = "Biological Sex" length = $ 1
VisitDate label = "Visit Date" length = $ 10
failDate label = "Failure Notification Date" length = $ 10
sbp label = "Systolic Blood Pressure"
dbp label = "Diastolic Blood Pressure"
bpUnits label = "Units (BP)" length = $ 5
pulse label = "Pulse"
pulseUnits label = "Units (Pulse)" length = $ 9
position label = "Position" length = $ 9
temp label = "Temperature" format = 5.1
tempUnits label = "Units (Temp)" length = $ 1
weight label = "Weight"
weightUnits label = "Units (Weight)" length = $ 2
pain label = "Pain Score"
;
然后,您可以在创建 ATTRIB 语句时使用该宏变量。
data want;
attrib &common
Xvar1 length=8 label='Extra Variable 1'
Xvar2 length=$20 label='Extra Variable 2'
;
set have;
run;