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...
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
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®
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
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!
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.