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 2024

Innovate_SAS_Blue.png

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. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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