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!
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.