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.
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;
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.