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 (December 2002, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 2 Dec 2002 17:19:26 +0100
Reply-To:     Peter Crawford <peter.crawford@DB.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Peter Crawford <peter.crawford@DB.COM>
Subject:      Re: Macro query (quite long - sorry)
Comments: To: David Yeates <david.yeates@UHCE.OX.AC.UK>
Content-type: text/plain; charset=iso-8859-1

macro option parmbuff loads the parameter string of the call, into macro variable &syspbuff Then you parse that ...... including the surrounding "(" and ")"

Good Luck Peter Crawford ps why are you not building the format from a cntlin dataset ?

Datum: 02/12/2002 16:11 An: SAS-L@LISTSERV.UGA.EDU

Antwort an: David Yeates <david.yeates@UHCE.OX.AC.UK>

Betreff: Macro query (quite long - sorry) Nachrichtentext:

Hi All,

I have a requirement for passing parameters via a macro call which I then use in a format procedure call to define groupings on a dataset variable.

The problem is the parameter itseld may contain a comma (,).

I have got round this by passing the parameter with comms replaced by plus signs (+), and replacing them in a macro which builds the format procedure.

I end up with (for example)

PROC FORMAT; VALUE ICD7F 4201,4300-4309 = "1" 5120-5129 = "2" OTHER = "0" ;

Now this is fine and a run of the macro (XPANDF) appears later but I also want to set up the corresponding as (again, for example)

PROC FORMAT; VALUE ICD7C 1 = "4201,4300-4309" 2 = "5120-5129" ;

Referring to the macro below I (naively as it turned out) thought that it would be sufficient to replace line 33 ( %qsubstr(&temp,1,%eval(&f-1))%str( = )&n ) with the line &n%str( = )%qsubstr(&temp,1,%eval(&f-1)) but this gave me errors and I have not been able to get the correct syntax to give me what I need.

Could anyone let me know where I am going wrong here - I guess it's related to appropriate quoting but I just can't get it right.

Help ?

<SNIPPED LOG STUFF...> NOTE: AUTOEXEC processing completed.

1 %* -------------------------------------------------------------- -----; 2 %* macro XPANDF expands a string of type 4201+4300-4309/5120- 5129 into; 3 %* a form contributing to a PROC FORMAT statement ; 4 %* %XPAND(4201+4300-4309/5120-5129) ->> ; 5 %* 4201,4300-4309 = "1" 5120-5129 = "2" ; 6 %* -------------------------------------------------------------- -----; 7 %* Use as:- ; 8 %* PROC FORMAT; ; 9 %* VALUE ICD7F ; 10 %* %XPANDF(4201+4300-4309/5120-5129) OTHER="0" ; ; 11 %* To produce:- ; 12 %* PROC FORMAT; ; 13 %* VALUE ICD7f ; 14 %* 4201,4300-4309 = "1" 5120-5129 = "2" OTHER = "0" ; ; 15 %* -------------------------------------------------------------- -----; 16 %macro XPANDF(string); 17 %local n temp word; 18 %* put a dummy last word; 19 %let temp = %qleft(&string%str(/?)); 20 %let n = %index(&temp,+); 21 %* replace all occurencs of a plus sign (+) with a comma (,); 22 %do %while (&n > 0); 23 %let word = %qsubstr(&temp,1,%eval(&n-1))%str(,) %qsubstr(&temp,%eval(&n+1)); 24 %let temp = %qleft(&word); 25 %let n = %index(&temp,+); 26 %end; 27 %* split the individual groups and generate appropriate line; 28 %let n = 1; 29 %let f = %index(&temp,/); 30 %do %while (&f > 0); 31 %if (&f > 1) %then 32 %do; 33 %qsubstr(&temp,1,%eval(&f-1))%str( = )&n 34 %end; 35 %let n = %eval(&n + 1); 36 %let temp = %qleft(%qsubstr(&temp,%eval(&f+1))); 37 %let f = %index(&temp,/); 38 %end; 39 %mend; 40 %* ; 41 %* run macro as a test ------->>; 42 %* ; 43 %let icd7 = 4201+4300-4309/5120-5129; 44 proc format page; 45 value icd7f 46 %xpandf(&icd7) other = "0" ; NOTE: Format ICD7F has been output. NOTE: The PROCEDURE FORMAT printed page 1. NOTE: PROCEDURE FORMAT used: real time 0.04 seconds cpu time 0.04 seconds

NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414 NOTE: The SAS System used: real time 0.18 seconds cpu time 0.13 seconds

<SAS OUTPUT FILE...>

' FORMAT NAME: ICD7F LENGTH: 1 NUMBER OF VALUES: 4 ' ' MIN LENGTH: 1 MAX LENGTH: 40 DEFAULT LENGTH 1 FUZZ: STD '

'START 'END 'LABEL (VER. 8.2 02DEC2002:15:46:59)'

' 4201' 4201'1 ' ' 4300' 4309'1 ' ' 5120' 5129'2 ' '**OTHER** '**OTHER** '0 '

--

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet.

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.


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