Skip to content

Instantly share code, notes, and snippets.

@statgeek
Created January 23, 2019 23:36
Show Gist options
  • Select an option

  • Save statgeek/5c8f4e769e898353d7e8115610f5ad5e to your computer and use it in GitHub Desktop.

Select an option

Save statgeek/5c8f4e769e898353d7e8115610f5ad5e to your computer and use it in GitHub Desktop.
SAS - Import Statistics Canada Table Numbers
%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