DATA Step, Macro, Functions and more

Selecting Zipcodes starting with a character symbol

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

Selecting Zipcodes starting with a character symbol

Hi ,

    I need to filter out data in the "ZIP" column of a data set. It has few values which start with a character variable (A-Z). How can I filter them in a dataset of 1000000 rows. Column "ZIP" is a categorical variable.

    I did try this approach but there seems something to be wrong :

proc sql;

delete * from dataset where zip = '^[A-Z]';

quit;

The log says no rows are selected. Please advice !

Thanks ,

Minal


Accepted Solutions
Solution
‎04-02-2014 07:17 AM
Respected Advisor
Posts: 3,777

Re: Selecting Zipcodes starting with a character symbol

data _null_;
  
input zip $;
   notdigit = verify(first(zip),'0123456789');
   put _all_;
  
cards;
10123
u9900
90210
;;;;
   run;

15         data _null_;
16            input zip $;
17            notdigit = verify(first(zip),'0123456789');
18            put _all_;
19            cards;

zip=
10123 notdigit=0 _ERROR_=0 _N_=1
zip=u9900 notdigit=
1 _ERROR_=0 _N_=2
zip=
90210 notdigit=0 _ERROR_=0 _N_=3

View solution in original post


All Replies
Regular Contributor
Posts: 195

Re: Selecting Zipcodes starting with a character symbol

proc sql;

  select *

  from have

  where anayalpha(ZIP);

quit;


Occasional Contributor
Posts: 13

Re: Selecting Zipcodes starting with a character symbol

Thanks for the reply. But on running the code I get the following error :

23         proc sql;

24           select *

25           from project.a1

26           where anayalpha(ZIP);

ERROR: Function ANAYALPHA could not be located.

But anyways I tried running this :

proc sql;

    select * from project.a1 where prxmatch('/^[A-Z]/', zip);

quit;

and it worked.

Thanks,

Minal

Super User
Super User
Posts: 7,392

Re: Selecting Zipcodes starting with a character symbol

Typo in word anyalpha:

where anyalpha(ZIP);

Frequent Contributor
Posts: 106

Re: Selecting Zipcodes starting with a character symbol

it should be

if anyalpha(zip)=1;

1 is for if zip starts with character value.

Solution
‎04-02-2014 07:17 AM
Respected Advisor
Posts: 3,777

Re: Selecting Zipcodes starting with a character symbol

data _null_;
  
input zip $;
   notdigit = verify(first(zip),'0123456789');
   put _all_;
  
cards;
10123
u9900
90210
;;;;
   run;

15         data _null_;
16            input zip $;
17            notdigit = verify(first(zip),'0123456789');
18            put _all_;
19            cards;

zip=
10123 notdigit=0 _ERROR_=0 _N_=1
zip=u9900 notdigit=
1 _ERROR_=0 _N_=2
zip=
90210 notdigit=0 _ERROR_=0 _N_=3
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 233 views
  • 3 likes
  • 5 in conversation