DATA Step, Macro, Functions and more

Macro SAS - %CMPRES function

Reply
Occasional Contributor
Posts: 11

Macro SAS - %CMPRES function

[ Edited ]

i resolve to 8.png

I resolve to 8.what  does it signifies?

 

code 

(data sets frrom SAS Macro Programming Made Easy)

options mprint mlogic symbolgen;
%macro trimname(namevalue);
%cmpres(%qupcase(%sysfunc(
compress(%superq(namevalue),%str(, ),kA))))
%mend trimname;

proc tabulate data=work.ytdsales
(where=(upcase(author)=
"%trimname(%str(wright, LINDA, Lisa))"))
;
title "Title list for %trimname(%str(wright, linda, lisa))";
class booktitle datesold bookfmt;
tables booktitle=' ',
datesold="Quarter Sold" all='**Total Books Sold',
all="Books Sold"*(bookfmt all='Total')*n=' '*f=3. / misstext='0';
format datesold qtr.;
run;

Super User
Posts: 17,829

Re: MacoSAS

The question is unclear. 

Occasional Contributor
Posts: 11

Re: MacoSAS

Actually in the figure there is "I" which shows it resolve to 8.I am not able to understand why it resolves to 8.

Trusted Advisor
Posts: 1,128

Re: MacoSAS

The reason the I resolves to 8 is that it is set within the macro trimname to a value of 8 with %let statement. As per the image, the macro is supposed to loop if I ne 0, since 8 ne 0 the loop executes and the text is compressed to keep only the alphabets.

 

I am not sure of the purpose as I see the macro trimname is used to put  the text in the title.

Thanks,
Jag
Super User
Posts: 17,829

Re: MacoSAS


Tap222 wrote:

Actually in the figure there is "I" which shows it resolve to 8.I am not able to understand why it resolves to 8.


 

Since there's no I in the code or %let, then it likely comes from the other macro CMPRES.

I do wonder why you're using both Compress function and compress macro function though. 

 

Extracting that code provides:

 

 %macro cmpres(text);
 %*********************************************************************;
 %*                                                                   *;
 %*  MACRO: CMPRES                                                    *;
 %*                                                                   *;
 %*  USAGE: 1) %cmpres(argument)                                      *;
 %*                                                                   *;
 %*  DESCRIPTION:                                                     *;
 %*    This macro returns the argument passed to it in an unquoted    *;
 %*    form with multiple blanks compressed to single blanks and also *;
 %*    with leading and trailing blanks removed.                      *;
 %*                                                                   *;
 %*    Eg. %let macvar=%cmpres(&argtext)                              *;
 %*                                                                   *;
 %*  NOTES:                                                           *;
 %*    The %LEFT and %TRIM macros in the autocall library are used    *;
 %*    in this macro.                                                 *;
 %*                                                                   *;
 %*********************************************************************;
 %local i;
 %let i=%index(&text,%str(  ));
 %do %while(&i ne 0);
   %let text=%qsubstr(&text,1,&i)%qleft(%qsubstr(&text,&i+1));
   %let i=%index(&text,%str(  ));
 %end;
 %left(%qtrim(&text))
 %mend;

 

 

 

Super User
Posts: 17,829

Re: MacoSAS

To find the macro definition, note the 5th line of your log, which provides the program from %cmpres auto call macro.
Ask a Question
Discussion stats
  • 5 replies
  • 394 views
  • 1 like
  • 3 in conversation