BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jojozheng
Quartz | Level 8

Hi everyone, 

I need to scrap data from this website https://www.addresses.com/zipcodes

I need to scrap all US states zip codes, I don't want to copy&past 56 times by manual. Anyone knows how to to do it? Thank you.

I want all cloumns in following page, but I don't want to manually do it. If I do it manually, I need to click states to search over 50 times...

2018-09-20 12_51_24-AL ZIP Code Lookup _ Addresses.com.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
JasonDiVirgilio
Quartz | Level 8

Maybe scraping a website is not what you want to do...have you tried the Zipcode dataset?

 

proc print data=sashelp.zipcode;
where statecode='AL';
run;

 

...or other SAS-provided resources https://support.sas.com/downloads/download.htm?did=122546

 

View solution in original post

4 REPLIES 4
danielduval0
SAS Employee

Unfortunately, SAS will not be your best tool for web scraping.

 

I recommend using something like the Scraper Chrome add-on : https://chrome.google.com/webstore/detail/scraper/mbigbapnjcgaffohmbkdlecaccepngjd?hl=en

 

This allows you to highlight any table on a webpage, right-click and hit "scrape", and you can then export the table as a CSV file. You can then import that CSV file into SAS and begin analyzing the data.

 

You can also pip install the BeautifulSoup4 package in Python if you would like to automatically web scrape certain pages, however it can sometimes be extremely tedious and if you are simply trying to scrape some data and perform some analyses on it, I recommend using something like the Scraper Chrome add-on.

 

SAS unfortunately is not the best tool to web scrape data. For example, the following code scrapes only the zip code portion of the table you wanted to scrape from https://www.addresses.com/zip-codes-by-state/alabama :

 

filename HTMLtext "C:\Users\daduva\Desktop\WebScrape\HTML_Output.txt";


proc http
	method='GET'
	url="https://www.addresses.com/zip-codes-by-state/alabama"
	out=HTMLtext;
run;

data zipcodes;
infile "C:\Users\daduva\Desktop\WebScrape\HTML_Output.txt" TRUNCOVER dlm='"';
input @'<a href="/zip-code-lookup/' zipcode :$30. @;
run;

proc sort data=zipcodes NODUP;
by zipcode;
run;

I hope this post was helpful.

Best Regards,


 


Daniel DuVal


SAS Technical Support


+1 (919) 531-2211


SAS ▪ SAS Campus Drive ▪ Cary, NC  27513


SAS® … THE POWER TO KNOW®

jojozheng
Quartz | Level 8
Thank you! I tried the code, it seems like it can catch a part of data, but not all of them. But thank you so much for your help!
JasonDiVirgilio
Quartz | Level 8

Maybe scraping a website is not what you want to do...have you tried the Zipcode dataset?

 

proc print data=sashelp.zipcode;
where statecode='AL';
run;

 

...or other SAS-provided resources https://support.sas.com/downloads/download.htm?did=122546

 

jojozheng
Quartz | Level 8
Thank you for this useful tip! It seems like SASHELP is a useful folder, not just sample data.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 3494 views
  • 3 likes
  • 3 in conversation