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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

The SUBSTR function permits this:

 

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

View solution in original post

2 REPLIES 2

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 2 replies
  • 2577 views
  • 2 likes
  • 3 in conversation