Variable_name
input(Oldvar,best.)
put(Oldvar,best.)
Variable_name_1
input(Oldvar_,best.)
put(Oldvar_,best.)
How to add an underscore after oldvar so variable_1 becomes input(Oldvar_,best.) put(Oldvar_,best.)
Some context would help.
Are you trying to create a new variable from something where you don't actually know the name of the variable? If so, how are you getting "oldvar" to begin with?
What if there is already a variable "oldvar_" in the data set in use?
Yes creating a new variable,but this is how the variable is given by user ,but it has to be changed to an underscore as all other variables will be changes to an underscore as well.
Is it given by the user as a macro variable? How is it specified. We need a lot more details here. It could be as simple as macro variables with a period.
@SASPhile wrote:
Yes creating a new variable,but this is how the variable is given by user ,but it has to be changed to an underscore as all other variables will be changes to an underscore as well.
Not a macro variable. but in dataset
Out_Variable In_variable
New_Var input(oldvar,best.)
The input dataset has oldvar_ as variable name instead.so the new_var equals to input(oldvar_,best.)
More details. How do you know that oldvar will be converted?
@SASPhile wrote:
Yes creating a new variable,but this is how the variable is given by user ,but it has to be changed to an underscore as all other variables will be changes to an underscore as well.
This doesn't quite make sense to me. If "all other variables will be changed(sic) to an underscore" then where does a user providing a name have any impact? It sounds like you are doing the same thing for all variables in the data set.
And HOW does the user provide the information on the variable name.
Since you are specifying a BEST format how can you be sure that the "user" never specifies a character variable that BEST will not work for? And it actually appears as if at least two variables are concerned: Variable_name AND Oldvar.
You mean this ?
data have;
x='input(Oldvar,best.)';
want=tranwrd(x,',','_,');
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: