BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jbencina
Calcite | Level 5

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; 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You need to create a macro variable and then pass that to the code.

 

http://support.sas.com/documentation/cdl/en/mcrolref/67912/HTML/default/viewer.htm#n1y2jszlvs4hugn14...

 

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;

View solution in original post

1 REPLY 1
Reeza
Super User

You need to create a macro variable and then pass that to the code.

 

http://support.sas.com/documentation/cdl/en/mcrolref/67912/HTML/default/viewer.htm#n1y2jszlvs4hugn14...

 

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 1820 views
  • 0 likes
  • 2 in conversation