BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Konkordanz
Pyrite | Level 9

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Oligolas
Barite | Level 11

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 -

View solution in original post

2 REPLIES 2
Oligolas
Barite | Level 11

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 -

Konkordanz
Pyrite | Level 9

Thank you, that works!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 697 views
  • 1 like
  • 2 in conversation