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

I am trying to join a years worth of tables together while adding a field 'Reprting_Month'.  What I have isn't working, I'm hoping it'll make enough sense to get the point accross.  

 

What I have;

consumer201611

field1 field1

 

consumer201610

field1 field1

 

What I want:

 

Consumer_Agg

201611 field1 field2

201610 field1 field2.

 

What I've tried so far is somethig like this:

 

data consumer_agg;

%macro dates;

set

%do date = 201511 %to 201611;

fdr.consumer&dates;

%end;

%mend;

end;

 

the code runs with no errors but has no output.  I know I've done this in the past but can't find my old code.  

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Try:

%macro dates;
%do date = 201511 %to 201611;
fdr.consumer&dates
%end;
%mend;

data consumer_agg;

set
%dates
;
end;

3 problems: 1) you never called the macro

 

2) by putting ; after the fdr.consumer&dates value you would have terminated the set statement with the first name.

3) The data step ended on encountering the %macro statement as that is one of the boundaries between procedures. I suspect you got some odd message in the log about a data set with 0 variables.

 

Use

Options mprint symbolgen;

to see the code that is generated by your actual macro code.

View solution in original post

5 REPLIES 5
Reeza
Super User

Have you tried the short cut methods instead of listing all (colon and/or - between first and last datasets)?

Or extracting all the names from SASHELP.VTABLE?

 

 

Reeza
Super User

data want;

set consumer2016: indsname=source;

dset_month = source;

run;

Steelers_In_DC
Barite | Level 11

I don't know what you mean by 'between'.  I've never seen that.  I'm not familiar wiith indsname either, when I run that I get:

 

does not contain any members

Reeza
Super User

@Steelers_In_DC wrote:

I don't know what you mean by 'between'.  I've never seen that.  I'm not familiar wiith indsname either, when I run that I get:

 

does not contain any members


INDSNAME is an option that creates a variable that can store the name of the dataset a record comes from, when appending multiple datasets together. 

 

Post your log. As long as you're on SAS 9.3+ this should work, if you're on 9.2 then it won't.

ballardw
Super User

Try:

%macro dates;
%do date = 201511 %to 201611;
fdr.consumer&dates
%end;
%mend;

data consumer_agg;

set
%dates
;
end;

3 problems: 1) you never called the macro

 

2) by putting ; after the fdr.consumer&dates value you would have terminated the set statement with the first name.

3) The data step ended on encountering the %macro statement as that is one of the boundaries between procedures. I suspect you got some odd message in the log about a data set with 0 variables.

 

Use

Options mprint symbolgen;

to see the code that is generated by your actual macro code.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1741 views
  • 1 like
  • 3 in conversation