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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1160 views
  • 1 like
  • 2 in conversation