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

Hello all,

 

I am running several models. My independent variables are called V1, V2, V3, etc...The output of the models (glmselect) returns the parameter estimates and P-Values. The effects in the output table can looks like this: V3 in case of a main effect, or like this: V4*V6, in case of an interaction.

In addition, I have a dataset called "cont" with two columns, one is "Names" the variables names (V1, V2, V3,...) and one is "Labels" with the labels.

 

My goal (and problem) is to replace the effect text (V2, V2*V3, etc...) with a one based on the labels. I want to do the following:

 

If the effect is a main effect, I want a new variable to get the label of the main effect from the "cont" dataset. If the effect is an interaction, I need somehow to get the first variable name before the'*', then get the second one after the '*', replace them both with the labels, and put them back together with an '*' between them, and to put all that in the same variable as the label of the main effects.

 

For example, if my model gave 3 lines (apart from intercept): V1, V2 and V1*V2, I want to replace the first column with a new one that will get the values: Age, Gender, Age*Gender. The values are the labels from "cont".

 

One last thing to remember, that I will always have an intecept in the table. The label is not on the "cont" dataset and should remain "intercept".

 

Can you please assist me on how to do this ? Tank you very much in advance.

 

Clarrification: The interactions are only up to 2 variables, nothing like this: V1*V2*V3 is possible.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

You can try something like this:

data cntlin;
set cont;
rename
  names=start
  labels=label
;
fmtname = 'labelformat';
type = 'C';
run;

proc format libary=work cntlin=cntlin;
run;

data want;
set have;
new_effect = ' ';
do i = 1 to countw(effect,'*');
  new_effect = catx('*',trim(new_effect),put(scan(effect,i,'*'),$labelformat.));
end;
run;
  

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

You can try something like this:

data cntlin;
set cont;
rename
  names=start
  labels=label
;
fmtname = 'labelformat';
type = 'C';
run;

proc format libary=work cntlin=cntlin;
run;

data want;
set have;
new_effect = ' ';
do i = 1 to countw(effect,'*');
  new_effect = catx('*',trim(new_effect),put(scan(effect,i,'*'),$labelformat.));
end;
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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1007 views
  • 1 like
  • 2 in conversation