I don't think you need the need the macros you have or any new macros that contain macro loops or &&& references.
This was not tested for obvious reasons but have relative few changes except to combine steps.
libname b14 xport '/folders/myfolders/HIV-Millennials/LLCP2014.XPT';
libname b15 xport '/folders/myfolders/HIV-Millennials/LLCP2015.XPT';
libname b16 xport '/folders/myfolders/HIV-Millennials/LLCP2016.XPT';
libname b17 xport '/folders/myfolders/HIV-Millennials/LLCP2017.XPT';
libname hiv_data '/folders/myfolders/HIV-Millennials';
data hiv_data.b_years;
length _STATE 8 ADDEPEV2 8 EDUCA 8 HIVTST6 8 MARITAL 8 SEX 8 SXORIENT 8 HLTHPLN1 8 TRNSGNDR 8 ;
set b14.llcp2014 b15.llcp2015 b16.llcp2016 b17.llcp2017 indsname=indsname;
year = input(substrn(indsname,length(indsname)-3),4.)
run;
proc format;
value educa 0='No College' 1='College or Degree';
value agecat 1='Millennials' 2='Non-millennials';
value sex 0='Male' 1='Female';
value health 0='No' 1='Yes';
value trnsgndr 1='Yes' 0='No';
value hiv 0='No' 1='Yes';
value sxorient 1='Straight' 2='Lesbian/Gay' 3='Bisexual' 4='Other';
value race 0='White' 1='Black' 2='Hispanic' 3='Other';
value state 0='West' 1='Southwest' 2='Midwest' 3='Southeast' 4='Northeast' 5='U.S. Territory';
value married 0='Not Married' 1='Married';
value depression 0='No previous depression' 1='Previous depression';
run;
data analysis(keep=_race _age_g ADDEPEV2 _state trnsgndr marital hivtst6 sex agecat hlthpln1 educa sxorient);
set hiv_data.b_years;
where sxorient in (1, 2, 3, 4) and marital in (1, 2, 3, 4, 5, 6) and
ADDEPEV2 in (1, 2) and educa in (1, 2, 3, 4, 5, 6) and trnsgndr in(1,2,3,4) and
hlthpln1 in (1, 2) AND _STATE IN(1,2,5:6,8:13,15:34,36:39,41:42,44:47,49:51,53:56,66,72) and
hivtst6 in (1, 2) and _race in (1, 2, 3, 4, 5, 6, 7, 8) and sex in(1,2);
if educa in(1, 2, 3, 4, 9) then educa=0;
if educa in(5, 6) then educa=1;
if sex=1 then sex=0;
if sex=2 then sex=1;
if _age_g in(1, 2) then agecat=1;
if _age_g in(3, 4, 5, 6) then agecat=2;
if hlthpln1=1 then healthcare=1;
if hlthpln1=2 then hlthpln1=0;
if hivtst6=1 then hivtst6=1;
if hivtst6=2 then hivtst6=0;
if ADDEPEV2 in(1) then ADDEPEV2=1;
if ADDEPEV2 in(2) then ADDEPEV2=0;
if _race in(1) then _race=0;
if _race in(2) then _race=1;
if _race in(7) then _race=2;
if _race in(3, 4, 5, 6, 8) then _race=3;
if trnsgndr in(1,2,3) then trnsgndr=1;
if trnsgndr=4 then trnsgndr=0;
if _state in(53, 30, 41, 32, 49, 56, 16, 6, 8, 2, 15) then _state=0;
/* */
/* verified, 11 */
/* if _state in(4, 35, 48, 40) then _state=1; */
/* verified, 4 no records at all */
if _state in(38, 46, 31, 20, 27, 19, 29, 55, 17, 18, 26, 39) then _state=2;
/* REFERENCE verified, 12 */
if _state in(5, 22, 28, 1, 47, 21, 54, 51, 11, 37, 38, 13, 12, 10, 24) then
_state=3;
/* verified, 15 */
if _state in(42, 36, 50, 44, 9, 23, 34, 33, 25) then _state=4;
/* verified, 9 */
if _state in(66, 72) then _state=5;
/* verified, 2 */
if marital in(2, 3, 4, 5, 6) then marital='0';
if marital in(1) then marital='1';
run;
* sort the appended data by sex ;
proc sort data=analysis;
by sex;
run;
* run frequency/association testing on covariates against variable of interest ;
proc freq data=analysis;
tables (ADDEPEV2 sex _race marital _state trnsgndr sxorient hlthpln1 educa) * agecat / chisq;
tables (ADDEPEV2 sex agecat _race marital _state trnsgndr sxorient hlthpln1 educa) * hivtst6 / chisq;
format sex sex. agecat agecat. _race race. marital married.
_state state. sxorient sxorient. hlthpln1 health.
educa educa. trnsgndr trnsgndr. hivtst6 hiv. ADDEPEV2 depression.;
run;
/* logistic regression of covariates against ever been told had depressive diagnosis */
proc logistic data=analyisl;
class hivtst6(ref='1') ADDEPEV2(ref='1') sex(ref='0') agecat(ref='2')
_race(ref='0') marital(ref='0') _state(ref='2') trnsgndr(ref='0')
sxorient(ref='1') hlthpln1(ref='0') educa(ref='0');
model hivtst6=ADDEPEV2 sex agecat _race marital _state trnsgndr sxorient hlthpln1 educa;
run;
... View more