BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dshills
Calcite | Level 5

Hello:

I am trying to read in several SAS datasets for US states, each with a filename that has the format <statename>births i.e. ARnew, AZnew, CAnew,

I have 45 such datasets that I want to combine. I am using a do-loop for this but get an error saying "work.set.data. does not exist". What am I doing wrong?

libname proj '... ';

%let statelist=%str(ak,ar,al,.....wi,wv);

%macro combine;

data test;

%do k=1 %to 45;

%let state=%sysfunc(strip(%sysfunc(scan(&statelist,&k,','))));

set proj.&state.new

%end;

;

run;

%mend;

%combine;

Thanks

Dana

2 ACCEPTED SOLUTIONS

Accepted Solutions
dshills
Calcite | Level 5

I made the change but this didn't work.

libname proj '... ';

%let statelist=%str(ak,ar,al,.....wi,wv);

%macro combine;

data test;

%do k=1 %to 45;

set

%let state=%sysfunc(strip(%sysfunc(scan(&statelist,&k,','))));

proj.&state.new

%end;

;

run;

%mend;

%combine;

I still get the message

"work.set.data does not exist."

View solution in original post

Astounding
PROC Star

The word SET does not belong inside the %DO loop.  Move it to before the %DO statement, leaving everything else as is.

View solution in original post

5 REPLIES 5
ballardw
Super User

One thing do check with unexpected macro results is to turn on the macro inspection options:

If you tried:

options mprint;

%combine;

You would likely find in the log:

Set proj.aknew set proj.arnew  and so forth.

YOu did not put your SET in the correct place so SAS thinks you are looking for a data set name SET.

Use:

set

%let state=%sysfunc(strip(%sysfunc(scan(&statelist,&k,','))));

proj.&state.new

%end;

;  /* now this ; properly closes the SET statement*/

dshills
Calcite | Level 5

I made the change but this didn't work.

libname proj '... ';

%let statelist=%str(ak,ar,al,.....wi,wv);

%macro combine;

data test;

%do k=1 %to 45;

set

%let state=%sysfunc(strip(%sysfunc(scan(&statelist,&k,','))));

proj.&state.new

%end;

;

run;

%mend;

%combine;

I still get the message

"work.set.data does not exist."

Astounding
PROC Star

The word SET does not belong inside the %DO loop.  Move it to before the %DO statement, leaving everything else as is.

ballardw
Super User

copy and paste lost the %do loop. sorry. Yes SET OUTSIDE the do loop per Astounding.

dshills
Calcite | Level 5

Thank You to ballardw & astounding!

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
  • 5 replies
  • 2020 views
  • 0 likes
  • 3 in conversation