BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
fengyuwuzu
Pyrite | Level 9

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

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

11 REPLIES 11
Haikuo
Onyx | Level 15

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

 

  if limit_set_period = "Day" then limit_set_period = "Daily";
fengyuwuzu
Pyrite | Level 9
Thank you. Do you know why replace does not work?
Haikuo
Onyx | Level 15

It is simply not a legit SAS code.

Reeza
Super User

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

 

 

fengyuwuzu
Pyrite | Level 9
Thanks. I googled and did not see clearly which software it is. Not I see it is Stata.
fengyuwuzu
Pyrite | Level 9

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

Haikuo
Onyx | Level 15

Put this statement right after data statement:

data want;
length limit_set_period $10 ;
set have;
blah blah;
run;
fengyuwuzu
Pyrite | Level 9
that is where I put it. It does not work. very strange.
Astounding
PROC Star

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

 

format limit_set_period;

 

 

fengyuwuzu
Pyrite | Level 9
yes, this works!! Thanks!
Haikuo
Onyx | Level 15

Would you mind sharing your code?

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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
  • 11 replies
  • 1793 views
  • 1 like
  • 4 in conversation