data one; input bankname $1-20; length bankname $20; cards; new york bank new york bank. NEW YORK bank new york bnk new yrk bank ne york bank neww york bank nnew york bank ew york bank new york mets ; run; data two; set one; where bankname=*'new york bank'; run; data three; set one; where soundex(bankname)=soundex('new york bank'); run; data four; set one; banks=soundex(bankname); test=soundex('new york bank'); run;
Datasets two and three have no observations. Dataset four looks like this:
new york bank, 562152, N62152
...
new york mets, 562532, N62152
I also tried it in a proc sql and had similar results. When I use =* or soundex on a variable, it does not output the leading character. When I use it on a constant, the output looks as I expect it to. What am I doing wrong? Thanks
Show your LOG. Copy from the log and paste into a text box.
For set Two I get:
Obs | bankname |
---|---|
1 | new york bank |
2 | new york bank. |
3 | NEW YORK bank |
4 | new york bnk |
5 | new yrk bank |
6 | ne york bank |
7 | neww york bank |
8 | nnew york bank |
For three:
Obs | bankname |
---|---|
1 | new york bank |
2 | new york bank. |
3 | NEW YORK bank |
4 | new york bnk |
5 | new yrk bank |
6 | ne york bank |
7 | neww york bank |
8 | nnew york bank |
And for Four:
Obs | bankname | banks | test |
---|---|---|---|
1 | new york bank | N62152 | N62152 |
2 | new york bank. | N62152 | N62152 |
3 | NEW YORK bank | N62152 | N62152 |
4 | new york bnk | N62152 | N62152 |
5 | new yrk bank | N62152 | N62152 |
6 | ne york bank | N62152 | N62152 |
7 | neww york bank | N62152 | N62152 |
8 | nnew york bank | N62152 | N62152 |
9 | ew york bank | E62152 | N62152 |
10 | new york mets | N62532 | N62152 |
And my log:
34 data one; 35 input bankname $1-20; 36 length bankname $20; 37 cards; NOTE: The data set WORK.ONE has 10 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 48 ; 49 run; 50 data two; 51 set one; 52 where bankname=*'new york bank'; 53 run; NOTE: There were 8 observations read from the data set WORK.ONE. WHERE bankname =* 'new york bank'; NOTE: The data set WORK.TWO has 8 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 54 55 data three; 56 set one; 57 where soundex(bankname)=soundex('new york bank'); 58 run; NOTE: There were 8 observations read from the data set WORK.ONE. WHERE SOUNDEX(bankname)=SOUNDEX('new york bank'); NOTE: The data set WORK.THREE has 8 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds 59 60 data four; 61 set one; 62 banks=soundex(bankname); 63 test=soundex('new york bank'); 64 run; NOTE: There were 10 observations read from the data set WORK.ONE. NOTE: The data set WORK.FOUR has 10 observations and 3 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
Slightly different code (this includes the proc sql example I mentioned), but it gets the point across.
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
68
69
70 data one;
71 input bankname $1-20;
72 length bankname $20;
73 cards;
NOTE: The data set WORK.ONE has 10 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
84 ;
85 run;
86
87 data two;
88 set one;
89 where bankname=* 'new york bank';
90 run;
NOTE: There were 0 observations read from the data set WORK.ONE.
WHERE bankname =* 'new york bank';
NOTE: The data set WORK.TWO has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
91
92 proc sql noprint;
93 create table three as
94 select * from one where bankname=*"new york bank";
NOTE: Table WORK.THREE created, with 0 rows and 1 columns.
95 quit;
NOTE: PROCEDURE SQL used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
96
97 data four;
98 set one;
99 where soundex(bankname)=soundex('new york bank');
100 run;
NOTE: There were 0 observations read from the data set WORK.ONE.
WHERE SOUNDEX(bankname)=SOUNDEX('new york bank');
NOTE: The data set WORK.FOUR has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.