I'm new to the SAS world and have been trying to figure this problem out. I have a list of variables in my data tables that could change (# included, or the names). I've been trying to make a dynamic code that runs the following code for any number of Variables (A, B, C, etc.)
proc transreg data=WORK.'MY_DATA'n;
model boxcox(Var_A Var_B ...) = identity(DEP_VAR);
run;
I've been researching and found something along these lines. But I can't seem to figure out how to take the variable output below and use it in the function above. Any help would be appreciated!
PROC CONTENTS DATA = WORK.'MY_DATA'n
OUT=VAR_NAMES(KEEP = NAME) NOPRINT;
RUN;
DATA PARSE;
SET VAR_NAMES;
WHERE (NAME NOT IN ('DEP_VAR','ID_VAR'));
RUN;
You need to create a macro variable and then pass that to the code.
PROC CONTENTS DATA = WORK.'MY_DATA'n
OUT=VAR_NAMES(KEEP = NAME) NOPRINT;
RUN;
Proc SQL;
select name into :var_list separated by " "
from var_names
WHERE (NAME NOT IN ('DEP_VAR','ID_VAR'));
quit;
*Display the variable list in the log for verification;
%put &var_list;
Then apply that to your data:
proc transreg data=WORK.'MY_DATA'n;
model boxcox( &var_list. ) = identity(DEP_VAR);
run;
You need to create a macro variable and then pass that to the code.
PROC CONTENTS DATA = WORK.'MY_DATA'n
OUT=VAR_NAMES(KEEP = NAME) NOPRINT;
RUN;
Proc SQL;
select name into :var_list separated by " "
from var_names
WHERE (NAME NOT IN ('DEP_VAR','ID_VAR'));
quit;
*Display the variable list in the log for verification;
%put &var_list;
Then apply that to your data:
proc transreg data=WORK.'MY_DATA'n;
model boxcox( &var_list. ) = identity(DEP_VAR);
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.