Created
January 23, 2019 23:36
-
-
Save statgeek/5c8f4e769e898353d7e8115610f5ad5e to your computer and use it in GitHub Desktop.
SAS - Import Statistics Canada Table Numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %macro importStatCan(tableNum = , dset= ); | |
| filename out "%sysfunc(getoption(work))/&tableNum.-eng.zip"; | |
| proc http | |
| url="https://www150.statcan.gc.ca/n1/tbl/csv/&tableNum.-eng.zip" | |
| method="get" | |
| out=out; | |
| run; | |
| filename out; | |
| filename ext "%sysfunc(getoption(work))/&tableNum..csv"; | |
| filename inzip ZIP "%sysfunc(getoption(work))/&tableNum.-eng.zip"; | |
| data _null_; | |
| /* using member syntax here */ | |
| infile inzip(&tableNum..csv) | |
| lrecl=256 recfm=F length=length eof=eof unbuf; | |
| file ext lrecl=256 recfm=N; | |
| input; | |
| put _infile_ $varying256. length; | |
| return; | |
| eof: | |
| stop; | |
| run; | |
| proc import out=&dset. datafile=ext dbms=csv replace; | |
| guessingrows=max; | |
| run; | |
| filename ext clear; | |
| filename inzip clear; | |
| %mend; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment