## how to assign a number accordingly?

Solved
Super Contributor
Posts: 398

# how to assign a number accordingly?

Hello:

Thanks.

data test;

set test;

if prxmatch("m/date/i",var) > 0 then found=1;

else if prxmatch("m/den/i",var) > 0 then found=2;

else if prxmatch("m/pcr/i",var) > 0 then found=3;

.

.

.

else found=0;

run;

Accepted Solutions
Solution
‎06-09-2017 03:28 PM
PROC Star
Posts: 311

## Re: how to assign a number accordingly?

I'm assuming the appearance of the strings in question are mutually exclusive, but specifying the strings in the desired "found" order and the iterating through might do what you want:

``````data have;
input @1 text \$50.;
array strs{3} \$ ('date' 'den' 'pcr');
do i = 1 to dim(strs);
if prxmatch(prxparse(cats('/', strs(i), '/')), text) > 0 then found = i;
end;
datalines;
the word is date
you said pcr
den is the word
;
``````

All Replies
Solution
‎06-09-2017 03:28 PM
PROC Star
Posts: 311

## Re: how to assign a number accordingly?

I'm assuming the appearance of the strings in question are mutually exclusive, but specifying the strings in the desired "found" order and the iterating through might do what you want:

``````data have;
input @1 text \$50.;
array strs{3} \$ ('date' 'den' 'pcr');
do i = 1 to dim(strs);
if prxmatch(prxparse(cats('/', strs(i), '/')), text) > 0 then found = i;
end;
datalines;
the word is date
you said pcr
den is the word
;
``````
Super Contributor
Posts: 398

## Re: how to assign a number accordingly?

I have 300 rows.  Is there any way to avoid input all of the names?  Thanks.

PROC Star
Posts: 311

## Re: how to assign a number accordingly?

It would help me if you'd define your issue better. 300 rows is not an issue. It's the number of strings you want to match and assign an order to that would make this tedious.

Super Contributor
Posts: 398

## Re: how to assign a number accordingly?

[ Edited ]

I have to repeat use prxmatch statement over 100 times,  I don't know when will be the end of the string.  My goal is to automatic assign number to the end of the string, insteading of typing 'found=number' many times.

Super User
Posts: 23,662

## Re: how to assign a number accordingly?

Then you need to change the logic. Given how you phrased the question the answer is correct. But that isn't your actual question.

So post a better example of your question. Also, make sure you try the answer.

PROC Star
Posts: 311

## Re: how to assign a number accordingly?

What I'm proposing would require modifying one line in your code to accomodate the strings you're looking for:

``array strs{3} \$ ('date' 'den' 'pcr');``

If you really have 150+ strings that you want to assign to "found = ##," do these strings reside in data in any way? If that's really the case, I think you'll be looking for a macro solution, but since I have .005% confidence that I understand you're problem, I'll wait until it's more clear, at which point you'll probably have many other valid solutions.

Super User
Posts: 23,662

## Re: how to assign a number accordingly?

Why does the number of rows matter?

Super User
Posts: 13,498

## Re: how to assign a number accordingly?

how many codes? How many "found" values need assignment?

Or are just looking to add a row number to the data?

Super Contributor
Posts: 398

## Re: how to assign a number accordingly?

Super Contributor
Posts: 398

## Re: how to assign a number accordingly?

My goal is to track which name need to be change in the future when I found the unmatch string.

PROC Star
Posts: 508

## Re: how to assign a number accordingly?

I would rather maintain a reference table for this kind of thing with record_load_dt as your audit columns.your table will have values as den 1 06/07/2017 some thing like thing that and you update this table as per your requireement or whenever you get new value

Super User
Posts: 13,498

## Re: how to assign a number accordingly?

ybz12003 wrote:

My goal is to track which name need to be change in the future when I found the unmatch string.

Is this supposed to be the name of a variable? If so your process is likely flawed, variable names should not change if they mean the same thing. If the value represented should be associated with another item such as a location or activity then the a separate varaible to hold the value of that location, activity or whatever is better instead of having names like Value_Cityx Value_CityY Value_Cityz.

You should be controlling the names of variables when they are created as well as other chracteristics as variable type, format, length and label.

☑ This topic is solved.