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.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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