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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
%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

View solution in original post

9 REPLIES 9
art297
Opal | Level 21

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.

Happy
Calcite | Level 5

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?.

art297
Opal | Level 21

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.

Hima
Obsidian | Level 7

Can you please let me know how the names appear in your data base. That way it will help us in coding.

Reeza
Super User

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.

Hima
Obsidian | Level 7

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)

Happy
Calcite | Level 5

Thanks Hima for yur reply

Ksharp
Super User
%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

Happy
Calcite | Level 5

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.:)

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 9 replies
  • 824 views
  • 0 likes
  • 5 in conversation