```Date: Tue, 16 Nov 2010 12:57:15 -0500 Reply-To: Xu Libin Sender: "SAS(r) Discussion" From: Xu Libin Subject: Re: Use symput to make a macro var Comments: To: toby dunn In-Reply-To: Content-Type: text/plain; charset="US-ASCII" Toby Dunn, Thanks a lot for rewriting the codes for me. This looks a lot more succint to me. It also introduced the function ifn which I am not aware of in SAS, although I have used the similar concept in Excel. I did a little change of the program and get the desired results. It is a very enlightening experience. Libin Data _Null_ ; retain MaxRec 0; Set SRT481_&YR End = Last ; By Tin_Typ Tin Tax_Prd Mft_CD ; If Last Then Call SymputX( "RecNum&YR" , Put( MaxRec , Z1. ) , 'G' ) ; Do _N_ = 1 By 1 Until( Last.MTF_CD ) ; Set SRT481_&YR ; Cnt = Sum( Cnt , 1 , 0 ) ; MaxRec = IfN( Cnt > MaxRec , Cnt , MaxRec ) ; End ; Run ; ________________________________ From: toby dunn [mailto:tobydunn@hotmail.com] Sent: Monday, November 15, 2010 4:31 PM To: Xu Libin; sas-l@listserv.uga.edu Subject: RE: Use symput to make a macro var This should help clean up your Data Step a bit... Data _Null_ ; If Last Then Call SymputX( "RecNum&YR" , Put( MaxRec , Z1. ) , 'G' ) ; Do _N_ = 1 By 1 Until( Last.MTF_CD ) ; Set SRT481_&YR End = Last ; By Tin_Typ Tin Tax_Prd Mft_CD ; Cnt = Sum( Cnt , 1 , 0 ) ; End ; MaxRec = IfN( Cnt > MaxRec , Cnt , MaxRec ) ; Run ; Toby Dunn "I'm a hell bent 100% Texan til I die" "Don't touch my Willie, I don't know you that well" > Date: Mon, 15 Nov 2010 15:21:20 -0500 > From: Libin.Xu@IRS.GOV > Subject: Use symput to make a macro var > To: SAS-L@LISTSERV.UGA.EDU > > Hi, All! > > I tried to use the following codes to create macro variable with > the value of maxcount. When I %put the value for the variable, I got an > error message > > that says > > %put Number of Records: &recnum05; > > WARNING: Apparent symbolic reference RECNUM05 not resolved. > > Number of Records: &recnum05 > > Can anyone give me some advice on this? Thanks. > > > > Libin > > > > *count the maximum number of TC records per module; > > %macro countRec(yr); > > data _null_; > > retain maxcount 0; > > length recnum&yr \$1; > > set srt481_&yr end=last; > > by tin_typ tin tax_prd mft_cd; > > if first.mft_cd then count=1; > > else count+1; > > if last.mft_cd and count>maxTCcount then maxcount=count; > > if last then do; > > call symput("recnum&yr",put(maxcount,z1.)); > > put "Maximum number of records in 20&yr: " maxcount; > > end; > > run; > > %mend countRec; > > %countRec(05); > > %put Number of Records: &recnum05; ```

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