DATA Step, Macro, Functions and more

How to replace part of variable values?

Accepted Solution Solved
Reply
Contributor
Posts: 34
Accepted Solution

How to replace part of variable values?

I'm trying to replace only part of a value for one variable, so it matches to merge with another dataset based on this Facility ID. Don't worry about the contaminant or value variables, I just left them in there for the example. So, I want to be able to change the facility name from WP001574 to WP531574, from WP001575 to WP531575, and so on. I just need to replace part of the value. How can I do this? Thanks!

 

 

Have:

 

data contam;
    input FacilityID FacilityName $ Contaminant $ Value;
    datalines;
            1           WP001574         a           5
            2           WP001575         d           10
            3           WP001576      b           2
            4           WP002475      c           8
            5           WP002476      e           30
            6           WP003843         a           2
            7           WP003843              a           5
            8           WP003844           b           8
            9           WP003845           c           20
            10         WP003846           d           30
            11        WP003847          e           55
;
run;

Want:

 

data contam;
    input FacilityID FacilityName $ Contaminant $ Value;
    datalines;
            1           WP531574         a           5
            2           WP531575         d           10
            3           WP531576      b           2
            4           WP532475      c           8
            5           WP532476      e           30
            6           WP533843         a           2
            7           WP533843              a           5
            8           WP533844           b           8
            9           WP533845           c           20
            10         WP533846           d           30
            11        WP533847          e           55
;
run;


Accepted Solutions
Solution
‎02-01-2017 09:24 AM
Super User
Posts: 5,497

Re: How to replace part of variable values?

The SUBSTR function permits this:

 

substr(facilityName, 3, 2) = '35';

View solution in original post


All Replies
Solution
‎02-01-2017 09:24 AM
Super User
Posts: 5,497

Re: How to replace part of variable values?

The SUBSTR function permits this:

 

substr(facilityName, 3, 2) = '35';

Respected Advisor
Posts: 3,799

Re: How to replace part of variable values?

[ Edited ]
☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 202 views
  • 2 likes
  • 3 in conversation