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.
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.
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?
data want;
set consumer2016: indsname=source;
dset_month = source;
run;
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
@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.
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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.