Search code examples
variablessasmacros

How to create a macro variable for all attrib that are used for multiple datasets


I have a long list of attributes that are used for multiple datasets in my SAS code, but I cannot figure out how to create a macro variable that will allow me to avoid re-entering in this long list of attributes, only macro variables that would allow me to do things like repeat the sysUser or date. My list of attributes is in the code below:

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";

Can anyone tell me how I can create a macro variable that would code for all of this?


Solution

  • Since you seem to want to store PART of a single statement into a macro variable that should be easy enough.

    %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"
    ;
    

    You can then use that macro variable when making your ATTRIB statement.

    data want;
      attrib &common
        Xvar1 length=8 label='Extra Variable 1'
        Xvar2 length=$20 label='Extra Variable 2'
      ;
      set have;
    run;