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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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