DATA Step, Macro, Functions and more

repalce certain values for a variable

Accepted Solution Solved
Reply
Super Contributor
Posts: 318
Accepted Solution

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
Respected Advisor
Posts: 3,156

Re: repalce certain values for a variable

Posted in reply to fengyuwuzu

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

 

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

View solution in original post


All Replies
Solution
‎02-25-2016 11:15 AM
Respected Advisor
Posts: 3,156

Re: repalce certain values for a variable

Posted in reply to fengyuwuzu

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

 

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

Re: repalce certain values for a variable

Thank you. Do you know why replace does not work?
Respected Advisor
Posts: 3,156

Re: repalce certain values for a variable

Posted in reply to fengyuwuzu

It is simply not a legit SAS code.

Super User
Posts: 19,876

Re: repalce certain values for a variable

Posted in reply to fengyuwuzu

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

 

 

Super Contributor
Posts: 318

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: 318

Re: repalce certain values for a variable

Posted in reply to fengyuwuzu

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

Respected Advisor
Posts: 3,156

Re: repalce certain values for a variable

Posted in reply to fengyuwuzu

Put this statement right after data statement:

data want;
length limit_set_period $10 ;
set have;
blah blah;
run;
Super Contributor
Posts: 318

Re: repalce certain values for a variable

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

Re: repalce certain values for a variable

Posted in reply to fengyuwuzu

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

 

format limit_set_period;

 

 

Super Contributor
Posts: 318

Re: repalce certain values for a variable

Posted in reply to Astounding
yes, this works!! Thanks!
Respected Advisor
Posts: 3,156

Re: repalce certain values for a variable

Posted in reply to fengyuwuzu

Would you mind sharing your code?

☑ This topic is solved.

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

Discussion stats
  • 11 replies
  • 310 views
  • 1 like
  • 4 in conversation