I coded a macro loop to get a value size for each month(loop), and then want to merge all size for every month into one dataset, but I have difficulty to achieve this purpose. Let me illustrate my attempt.For each loop I will get one dataset containing firmid and size, but for each loop the firmid may be different (most of them are overlapped). For instance, month 1 would be like
firmid size
1 100
2 150
5 130
month 2 would be something like
firmid size
1 120
2 140
4 100
What I want to acheive is something like
firmid size(m1) size(m2)
1 100 120
2 150 140
4 . 100
5 130 .
Please help. Thanks.
Yes, ou could merge or SQL full join those results.
One way to do it dynamically is that in your loop (depending on the logic there...?) is to build som kind of dynamic SAS-code, which you execute in some point, i.e. using call execute.
Do you have the same data source for each loop? If so, what is the logic for creating size? Perhaps there is an easier way to solve the whole problem...
Since you're asking about a basic merge, I prefer to skip references to macro language and skip trying to automate the process. Here's a simple solution for two data sets. Assuming they are already sorted by FIRMID:
data want;
merge month1 (rename=(size=size_m1))
month2 (rename=(size=size_m2));
by firmid;
run;
It should be easy enough to extend that to more than 2 data sets.
Good luck.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.