turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- How do I compare two fields one with leading zeros...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-11-2016 07:00 PM

Hello all,

I have two Data Bases that store a field room, one has it with leading zeros and one without, the hitch is these rooms can have a alpha charater? any ideas?

I had some 1100 false positives now with this just a 100 or so

I came up with this:

put(input(a.room,best4.),z4.) <> put(input(b.room,best4.),z4.)

I started with:

a.room <> b.room

but with data like:

a.room b.room

451a 0451a

451b 0451b

1 00001

21 00021

1-1 001-1

I am not sure what to try to get them down to the true diffences that I want. TIA -KJ

Accepted Solutions

Solution

08-12-2016
10:49 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-11-2016 07:41 PM

PRX functions can be handy,

```
data have;
input aroom$ broom$;
_b=prxchange('s/(^0*)([^0]+.+)/$2/o',-1,broom);
equal_or_not=ifc(aroom=_b,'Y','N');
cards;
451a 0451a
451b 0451b
1 00001
21 00021
1-1 001-1
451a 0451c
;
```

All Replies

Solution

08-12-2016
10:49 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-11-2016 07:41 PM

PRX functions can be handy,

```
data have;
input aroom$ broom$;
_b=prxchange('s/(^0*)([^0]+.+)/$2/o',-1,broom);
equal_or_not=ifc(aroom=_b,'Y','N');
cards;
451a 0451a
451b 0451b
1 00001
21 00021
1-1 001-1
451a 0451c
;
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-12-2016 10:31 AM

Sorry I did not say it but my comparison I was using is in a proc sql where, I will check out your function. I hope it works in a proc sql.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-12-2016 01:06 AM

data have; input aroom$ broom$; equal_or_not=(aroom=prxchange('s/^0+//',-1,broom)); cards; 451a 0451a 451b 0451b 1 00001 21 00021 1-1 001-1 451a 0451c ; run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-12-2016 10:58 AM

Both answers work equally well for my needs tie goes to the first response. thanks for your pointer on "prxchange"

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-12-2016 01:28 AM

Just a check, but You know that <> is max in SAS?

In most languages it means Not Equals and from your usage it looks like that's what your using it for?

The MIN and MAX operators are used to find the minimum or maximum value of two quantities. Surround the operators with the two quantities whose minimum or maximum value you want to know. The MIN (><) operator returns the lower of the two values. The MAX (<>) operator returns the higher of the two values.

http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000780367.htm

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-12-2016 10:27 AM - edited 08-12-2016 10:27 AM

Yes I am aware that <> is max, but in "proc sql" it works and works with SQL queries diectly thus we use it... I have been burned by it in data steps so it is playing a bit with fire.