DATA Step, Macro, Functions and more

Downloading zip files from US Census FTP site

Accepted Solution Solved
Reply
Contributor KAZ
Contributor
Posts: 25
Accepted Solution

Downloading zip files from US Census FTP site

The US Census Bureau makes TIGER/Line shapefiles available via a series of FTP sites.  The files are freely available and no account is needed to access the FTP site.  I am attempting to write a program that downloads those files.

 

I presumed a filename ftp statement was the way to go, but am running into problems.

 

* Copy files from US Census website to the specified directory;
filename _bcin ftp "ftp://ftp2.census.gov/geo/tiger/TIGER2010/ZCTA5/2010/tl_2010_24_zcta510.zip";
filename _bcout "C:\Temp\tl_2010_24_zcta510.zip" recfm=n;
data _null_;
   length msg $ 384;
   rc=fcopy('_bcin', '_bcout');
   if rc=0 then
      put 'Copied _bcin to _bcout.';
   else do;
      msg=sysmsg();
      put rc= msg=;
   end;
run;

quit;

I received the follwoing error: rc=5660215 msg=ERROR: Open failed for file _BCIN.

What is the proper filenane ftp statement for the remote file?

 

(alternative question: downloading US Census files must be a common task for mapping appications.  Are there any available macros out there that accomplishes this?)

 

 

I am running SAS v9.4, TS1M4.


Accepted Solutions
Solution
‎03-03-2017 03:25 PM
Trusted Advisor
Posts: 1,301

Re: Downloading zip files from US Census FTP site

[ Edited ]
filename _bcin ftp 'tl_2010_24_zcta510.zip'
cd='/geo/tiger/TIGER2010/ZCTA5/2010'
host='ftp2.census.gov'
user='anonymous'
passive binary recfm=s;

 

and, if fcopy doesn't work you can use a very simple data step instead

 

data _null_;
infile _bcin;
file _bcout;
input;
put _infile_;
run;

View solution in original post


All Replies
Solution
‎03-03-2017 03:25 PM
Trusted Advisor
Posts: 1,301

Re: Downloading zip files from US Census FTP site

[ Edited ]
filename _bcin ftp 'tl_2010_24_zcta510.zip'
cd='/geo/tiger/TIGER2010/ZCTA5/2010'
host='ftp2.census.gov'
user='anonymous'
passive binary recfm=s;

 

and, if fcopy doesn't work you can use a very simple data step instead

 

data _null_;
infile _bcin;
file _bcout;
input;
put _infile_;
run;
☑ This topic is solved.

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

Discussion stats
  • 1 reply
  • 230 views
  • 1 like
  • 2 in conversation