## repalce certain values for a variable

Solved
Super Contributor
Posts: 328

# repalce certain values for a variable

In my data set, the variable limit_set_period has both values of "Day" and "Daily". I want to change the "Day" values to "Daily" by

``replace limit_set_period = "Daily" if limit_set_period = "Day";``

but it does not work

any hints? Thanks

Accepted Solutions
Solution
‎02-25-2016 11:15 AM
Posts: 3,167

## Re: repalce certain values for a variable

You are close, but make sure the length is sufficient, then,

``  if limit_set_period = "Day" then limit_set_period = "Daily";``

All Replies
Solution
‎02-25-2016 11:15 AM
Posts: 3,167

## Re: repalce certain values for a variable

You are close, but make sure the length is sufficient, then,

``  if limit_set_period = "Day" then limit_set_period = "Daily";``
Super Contributor
Posts: 328

## Re: repalce certain values for a variable

Thank you. Do you know why replace does not work?
Posts: 3,167

## Re: repalce certain values for a variable

It is simply not a legit SAS code.

Super User
Posts: 23,776

## Re: repalce certain values for a variable

That's not valid SAS code...is there some reason you think it is?

Super Contributor
Posts: 328

## Re: repalce certain values for a variable

Thanks. I googled and did not see clearly which software it is. Not I see it is Stata.
Super Contributor
Posts: 328

## Re: repalce certain values for a variable

indeed I have a length issue. I got the new values "Dai" because the length was defined by "Day".

I defined the length by

``length limit_set_period \$10 ;``

before the set statement. I still got "Dai".

Posts: 3,167

## Re: repalce certain values for a variable

Put this statement right after data statement:

``````data want;
length limit_set_period \$10 ;
set have;
blah blah;
run;``````
Super Contributor
Posts: 328

## Re: repalce certain values for a variable

that is where I put it. It does not work. very strange.
Super User
Posts: 6,785

## Re: repalce certain values for a variable

Quite possibly the variable has a \$3. format associated with it.  Add just before the RUN statement:

format limit_set_period;

Super Contributor
Posts: 328

## Re: repalce certain values for a variable

yes, this works!! Thanks!
Posts: 3,167