# How to compare unordered string arrays

0

I have a string array that I make ahead of time that I need to compare to another string array that is prepared by my GAUSS program. The problem is that my program will create the string array in an arbitrary order. For a simple illustration, I may start with:

```string sa_1 = { "AGE", "INCOME", "RISK_TOLERANCE", "QALY" };
```

and need to compare it to another string array that might be in any order. What is the simplest way to do this?

0
accepted

The simplest way to make this comparison is by first sorting the string array created by your program and then doing a direct compare of the two string arrays like this:

```string sa_1 = { "AGE", "INCOME", "QALY", "RISK_TOL" };
string sa_2 = { "QALY", "INCOME", "RISK_TOL", "AGE" };

//sort string array based upon the first (and only) column
sa_2 = sortcc(sa_2, 1);

//compare the sorted 'sa_2' with the original string array
//using the string comparison operator \$==
if (sa_1 \$== sa_2);
print "sa_1 = " sa_1;
print "sa_2 = " sa_2;
else;
print "comparison failed";
endif;
```

This short program snippet should return:

```sa_1 =
AGE
INCOME
QALY
RISK_TOL
sa_2 =
AGE
INCOME
QALY
RISK_TOL
```

0
accepted

The simplest way to make this comparison is by first sorting the string array created by your program and then doing a direct compare of the two string arrays like this:

```string sa_1 = { "AGE", "INCOME", "QALY", "RISK_TOL" };
string sa_2 = { "QALY", "INCOME", "RISK_TOL", "AGE" };

//sort string array based upon the first (and only) column
sa_2 = sortcc(sa_2, 1);

//compare the sorted 'sa_2' with the original string array
//using the string comparison operator \$==
if (sa_1 \$== sa_2);
print "sa_1 = " sa_1;
print "sa_2 = " sa_2;
else;
print "comparison failed";
endif;
```

This short program snippet should return:

```sa_1 =
AGE
INCOME
QALY
RISK_TOL
sa_2 =
AGE
INCOME
QALY
RISK_TOL
```

• ### Aptech Systems, Inc. Worldwide Headquarters

Aptech Systems, Inc.
2350 East Germann Road, Suite #21
Chandler, AZ 85286

Phone: 360.886.7100
FAX: 360.886.8922

• ### Training & Events

Want more guidance while learning about the full functionality of GAUSS and its capabilities? Get in touch for in-person training or browse additional references below.

• ### Tutorials

Step-by-step, informative lessons for those who want to dive into GAUSS and achieve their goals, fast.

• ### Want to find out more?

Get a real answer from a real person

• ### Have a Specific Question?

Get a real answer from a real person

• Need Support?
• ### Support Plans

Premier Support and Platinum Premier Support are annually renewable membership programs that provide you with important benefits including technical support, product maintenance, and substantial cost-saving features for your GAUSS System or the GAUSS Engine.

• ### User Forums

Join our community to see why our users are considered some of the most active and helpful in the industry!