Duplicate an existing String Column

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Duplicate an existing String Column

I am trying to duplicate a string column. 

in a data step, I am using

oldvar=newvar

but in the output table the newvar comes back as "."

 

Is there a special option to duplicate the characters in a string variable?

I am on SAS EG 7.13


Accepted Solutions
Solution
‎04-05-2017 05:46 PM
Super User
Posts: 19,157

Re: Duplicate an existing String Column

No, there is no extra step required. My guess is 'newvar' isn't actually new but is somehow defined in the dataset already as a numeric field. Ensure that the variable name is new or make sure the types match up when re-assigning data.

 

 

View solution in original post


All Replies
Solution
‎04-05-2017 05:46 PM
Super User
Posts: 19,157

Re: Duplicate an existing String Column

No, there is no extra step required. My guess is 'newvar' isn't actually new but is somehow defined in the dataset already as a numeric field. Ensure that the variable name is new or make sure the types match up when re-assigning data.

 

 

Super User
Posts: 11,134

Re: Duplicate an existing String Column

To assign the value to the newvar you need to reverse the order:

 

newvar = oldvar;

 

The way you are doing it, using a variable that didn't exist before on the RIGHT side of = means that SAS created one to reference and since there wasn't any definition then the default is a numeric. And then without assigning a value it is initialized as missing.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 139 views
  • 1 like
  • 3 in conversation