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

I want to replace single observations in a dataset.

 

I have a var whose obs I want to change. Fir example each time my var =10, I want to replace it with 15 or another number or my choosing. How do I do this?'

I used to be able to do this with modify and replace statements, but have forgotten how to do it.

1 ACCEPTED SOLUTION

Accepted Solutions
CurtisMackWSIPP
Lapis Lazuli | Level 10

I prefer the SQL approach.

 

proc sql;
  update have
    set x1=15
   where x1=10;
quit;

One advantage is it will work if the data in not in a SAS dataset.

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26
data want;
    set have;
    if x1=10 then x1=15;
run;
--
Paige Miller
ballardw
Super User

"Observation" in SAS-speak is an entire "row of data" , "record" or similar. You want to change the value of a variable in specific observations, not "replace an observation".

 

CurtisMackWSIPP
Lapis Lazuli | Level 10

In the poster's defense, I they were thinking of the modify/replace syntax in which you must replace the entire record to change a single value.

CurtisMackWSIPP
Lapis Lazuli | Level 10

I prefer the SQL approach.

 

proc sql;
  update have
    set x1=15
   where x1=10;
quit;

One advantage is it will work if the data in not in a SAS dataset.

CurtisMackWSIPP
Lapis Lazuli | Level 10

If you really want to use the modify/replace style, my old paper should help.  https://www.lexjansen.com/pnwsug/2008/CurtisMack-Modify.pdf .  It is overkill for this case though.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 5 replies
  • 2620 views
  • 4 likes
  • 4 in conversation