DATA Step, Macro, Functions and more

append a value to an existing value

Reply
New Contributor
Posts: 2

append a value to an existing value

[ Edited ]

Hi @ll,@ll,

 

how can I append a value to an existing value? I want to look up a value from a column_1 in a column_2 and everytime there's a match it should write a specific value to a column_3. The tricky part (for me right now) is that, if an observation already got a specific value in column_3, the new match should append at the end of the first match with a "-".

 

Example:

 

In the final Table_1, I could use the "Block_done_with_scan" variable to mark all values in V1 and V2 as belonging to specific code 42.

 

Table_0:                      Table_1:

V1 | V2                         V1 | V2 | Match | Block_done_with_scan

1   | 2                            1   | 2   | 42-42  | 42

2   | 1                            2   | 1   | 42       | 42

2   | 2                            2   | 2   | 42-42  | 42

Super User
Super User
Posts: 7,942

Re: append a value to an existing value

Posted in reply to chewy_chicken78

Well, I am not following your text there very well, but the easiest way to append a value to an existing one is to use the string cat functions, e.g:

catx('-',match,"42");

The above is an eample of the catx() function.  The first parameter shows the delimiter, thats the character(s) which will divide each of the following elements.  After that is the elements.  Now if match is empty you will just get "42", no delimier as there is only one value, if match has something then it will go match + "-" + "42".

Ask a Question
Discussion stats
  • 1 reply
  • 164 views
  • 0 likes
  • 2 in conversation