LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2004, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 13 Jul 2004 16:30:11 -0400
Reply-To:     Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Subject:      Re: SAS Macro - merge

You cannot merge *in* a macro. You can use a macro to generate SAS DATA step code to merge.

So start by disentangling. Running your macro with the MPRINT option in effect, the code appears in the log. It is

data test; set contac; run;

data test(keep= indid indid1-indid1 ); merge wave1.w1adult test ; by indid; indid1=indid; run;

data test(keep= indid indid1-indid2 ); merge wave2.w2adult test ; by indid; indid2=indid; run;

data test(keep= indid indid1-indid3 ); merge wave3.w3adult test ; by indid; indid3=indid; run;

Analyze and debug that. If you wind up with something repetitive in nature, then consider crafting a macro to generate the code.

On Tue, 13 Jul 2004 08:25:10 -0700, Wini <wottoy@ADVALVAS.BE> wrote:

>Hi, > >I have a problem with merging datasets within a macro. I would like to >retain for each survey (in fact it are waves) the indid. Therefore I >create indidX = indid. For a wave were the indid is present I would >like to have that indid else a missing, but the only thing I get is a >matrix with all indids. (it seemst that the value from the first >datset, a list of all possible indids) is retained. > >The indid is called indid in all files, but I like to have a file with >indid1 indid2 indi3 > >suppose contac contains > >indid >1111 >1245 >2548 >3655 > > >wave1 contains a datset with > >indid > >1245 >3655 > >wave2 contains a datset with > >1245 >2548 > > >then I would like to have a dataset with > >indid indid1 indid2 >1111 . . >1245 1245 1245 >2548 . 2548 >3655 3655 . > >What is wrong with this code? > >%macro comb(bib,dsn,iniw,endw,sortvar,target,vars); >data &target; >set contac; >run; >%do i=&iniw %to &endw; >data &target(keep= indid &vars&iniw-&vars&i ); >merge &bib&i..w&i.&dsn &target ; >by &sortvar; >&vars.&i=indid; >run; >%end; >%mend; > >%comb(wave,adult,1,3,indid,test,indid); > >Thanks in advance!


Back to: Top of message | Previous page | Main SAS-L page