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: Call for Content

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!

Submit your idea!

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
  • 7 replies
  • 2056 views
  • 0 likes
  • 4 in conversation