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!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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