03-23-2016 05:01 AM
Using SAS EG 7.1.
Basically I want to merge
FATax&YEAR1.&MONTH with Y&YEAR2.&MONTH, but YEAR1 is NOT equal YEAR2.
FATax2015.&MONTH with Y&2014.&MONTH
I tried the below, but it doesn't seem to work.
%DO YEAR1=&FIRSTYR_Tax %TO &LASTYR_TAX;
%DO YEAR2=&FIRSTYR_Y %TO &LASTYR_Y;
%do i = 1 %to %sysfunc(countw(&monlist.));
%let month = %sysfunc(putn(%scan(&monlist.,&i.),z2.));
FATax&YEAR1.&MONTH(IN=A) Y&YEAR2.&MONTH (IN=B);
IF A AND B Or (A AND Age=0);
03-23-2016 05:33 AM - edited 03-23-2016 05:43 AM
Why are you creating a rod for your own back in the first place? I would first set your data together, get rid of the data elements in the dataset name - remember data set name, and variable names, are there for programming purposes Not to contain "data". Labels and observations are there to contain "data". If you put your data together, and you haven't posted any example data so I can't provide code, you can then simplfy your whole code to focus on one dataset, no need for looping, or macro or anything else, simple Base SAS programming.
If you can post some example test data - in the form of a datastep, I will show you how to process it into well strcutured data, and then how to program using Base SAS a very simple setup.
Edit: I also add the link to your other question, which is pretty much the same thing and caused by the same structural choices:
03-23-2016 05:51 AM
The merge is irrelevant to the strcuture of the data, it is exactly the same to merge one dataset with itself as many to many.
With regards to your second point, macro will not be more efficient. This is a fundamental lack of understanding of what macro is. Macro is a text generation tool, which generates Base SAS code. It and of itself does nothing. So the question is, is the code generated by the macro processor more efficient and than the datastep I provided. Now I haven't tested it, but as mine is one datastep, with one datastep, and therefore would incur only one read/write per operation, whereas the macro code would generate one step with one read/write per operation I would conclude that no, the macro method would be slower, not to mention the code itself is far more complicated to maintain.
The simple fact is that you have many datasets, which you are reading, and them merging together. A simpler method, is to put them all together in one step and then transpose the resulting dataset. This would have exactly the same output as your method, with two datasteps.
If there was some test data, I could proide code.
03-23-2016 05:45 AM
With this construct, the macro will create datasteps where
number of datasteps = cardinality of YEAR1 * cardinality of YEAR2 * cardinality of &monlist
which is a whole lot of datasteps
I guess you have some rule for the relationship of YEAR2 to YEAR1?
eg if the difference is 1, then
%DO YEAR1=&FIRSTYR_Tax %TO &LASTYR_TAX; %let year2 = %eval(&year1-1);