BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8

  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.)   

7 REPLIES 7
ballardw
Super User

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?

SASPhile
Quartz | Level 8

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.

Reeza
Super User

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.


 

SASPhile
Quartz | Level 8

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.)

 

Reeza
Super User

More details. How do you know that oldvar will be converted?

ballardw
Super User

@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.

Ksharp
Super User

You mean this ?

 

data have;
x='input(Oldvar,best.)';
want=tranwrd(x,',','_,');
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
  • 7 replies
  • 2230 views
  • 0 likes
  • 4 in conversation