I have merge step like belw which has to merge jan and feb months data to the main master thereby creating feb dataset.
Likewise in March, the master should be merged with jan,feb and march months data. though i was able to create a macro for reading
the required input files for a particular month correctly (that is for Feb month, jan and feb months data should be read)
but im helpless in automating the below step. Colud anyone help me out .
Thanks in advance.
data feb;
merge master(in=a) jan(in=b) feb(in=c);
by id;
if a;
run;
%let want_month=4 ; *must be number of month , 4 is April ; options mprint; %macro month; %let list=Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec; data %scan(&list,&want_month) ; merge master(in=a) %do i=1 %to &want_month ; %scan(&list,&i) %end; ; by id; if a; run; %mend month; %month
Ksharp
First, do you really want to merge the files, or do you really just want to add new records to the master file?
Second, regardless of whether you really want to merge or concatenate, I think it would be easiest if you either updated the master each month or, if that isn't possible, build a macro that accomplishes the task one month at a time.
Thanks for your reply.
Yes i only have to merge the files. Will try building a macro then ..
but other than this is there not any other better way?.
To answer your question the forum members would need to know more about your data. It would help if you could post example data for your master and, say, jan and feb, and what you want the resulting file to look like given that example data.
Can you please let me know how the names appear in your data base. That way it will help us in coding.
Since you're only keeping records in the master data set anyways (if a) then perhaps look at the update and modify options instead of a merge?
It depends on what your'e looking to do, so need more details as others have indicated.
Assuming that the table MASTER_FINAL is a data set that has January's data merged with your file. The table for this month is TABLE_1202.
%MACRO RUNTHIS(TABLEDT);
DATA MASTER;
MERGE MASTER_FINAL (IN=A) TABLE_&TABLEDT. (IN=B);
BY ID;
IF A;
RUN;
DATA MASTER_FINAL;
SET MASTER;
RUN;
%MEND;
%RUNTHIS(1202)
Thanks Hima for yur reply
%let want_month=4 ; *must be number of month , 4 is April ; options mprint; %macro month; %let list=Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec; data %scan(&list,&want_month) ; merge master(in=a) %do i=1 %to &want_month ; %scan(&list,&i) %end; ; by id; if a; run; %mend month; %month
Ksharp
Oh Great!!....Your code is really interesting ..Never thought that we can do iterations on a dataset mentioned within a merge step...!! Learnt sumthning new ..
Thanks alot Ksharp.:)
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.