Hi,
currently I have 4 datasets:
gb2018.dbf
gb2019.dbf
gb2020.dbf
gb2021.dbf
The logic of their names is always the same: "gb" and the year. Each year a new dataset will be added into the same path.
Importing one of them works with following code:
proc import datafile = '...PATH\gb2018.dbf'
out= Geb_2021
REPLACE
dbms = dbf;
run;
But actually I want a code for importing a flexible selection of these datasets into one SAS-Dataset. For example: If I select the years 2018-2020, the code shall import gb2018.dbf, gb2018.dbf and gb2020.dbf. Do you have an idea, how to code that?
Would be nice to get some help! Thank you!
Hi,
I would use a macro, for example:
%MACRO importDBF(yearFrom=, yearTo=);
%LOCAL year;
%DO year=&yearFrom. %TO &yearTo.;
PROC IMPORT DATAFILE = "...PATH\gb&year..dbf"
OUT= Geb_&year.
REPLACE
DBMS = dbf;
RUN;
%END;
%MEND importDBF;
%importDBF(yearFrom=2018, yearTo=2020);
- Cheers -
Hi,
I would use a macro, for example:
%MACRO importDBF(yearFrom=, yearTo=);
%LOCAL year;
%DO year=&yearFrom. %TO &yearTo.;
PROC IMPORT DATAFILE = "...PATH\gb&year..dbf"
OUT= Geb_&year.
REPLACE
DBMS = dbf;
RUN;
%END;
%MEND importDBF;
%importDBF(yearFrom=2018, yearTo=2020);
- Cheers -
Thank you, that works!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.