/******************* URBAN INSTITUTE MACRO LIBRARY *********************
: ListChangeDelim
Macro: Change delimiters in a macro variable list: default is change
Description
from spaces to commas. Optionally add prefix to list items.
: Function
Use
: Peter Tatian
Author
***********************************************************************/
ListChangeDelim(
%macro /** List to process **/
list , old_delim = %str( ), /** Old list delimiter **/
new_delim = %str(,), /** New list delimiter **/
prefix = , /** Prefix to add before list items (optional) **/
suffix = , /** Suffix to add after list items (optional) **/
quiet=N /** Suppress log messages? (Y/N) **/
);
/*************************** USAGE NOTES *****************************
:
SAMPLE CALL%ListChangeDelim( %str(a,b,c,d,e,f,g), old_delim=%str(,), new_delim=%str( ) );
returns the list with delimiters changed from , to blank space
ListChangeDelim( a b c d e f g, prefix=data. )
%
returns the list with data. prefixed to each item*********************************************************************/
/*************************** UPDATE NOTES ****************************
06/27/05 Peter A. Tatian
08/20/06 Added suffix= parameter.
02/23/11 PAT Added declaration for local macro vars.
*********************************************************************/
***** ***** ***** MACRO SET UP ***** ***** *****;
%
%local i item new_list;
***** ***** ***** ERROR CHECKS ***** ***** *****;
%
***** ***** ***** MACRO BODY ***** ***** *****;
%
%if not %mparam_is_yes( &quiet ) %then %do;
note_mput( macro=ListChangeDelim, msg=Processing list=&list )
%
%end;
= 1;
%let i %let item = %scan( &list, &i, &old_delim );
= ;
%let new_list
%do %while ( %length( &item ) > 0 );
= &new_list&prefix&item&suffix;
%let new_list
%let i = %eval( &i + 1 );
%let item = %scan( &list, &i, &old_delim );
%if &item ~= %then %let new_list = &new_list&new_delim;
%end;
%if not %mparam_is_yes( &quiet ) %then %do;
note_mput( macro=ListChangeDelim, msg=New list=&new_list )
%
%end;
&new_list
***** ***** ***** CLEAN UP ***** ***** *****;
%
%mend ListChangeDelim;
/************************ UNCOMMENT TO TEST ***************************
"ListChangeDelim: UI SAS Autocall Macro Library";
title "K:\Metro\PTatian\UISUG\Uiautos";
filename uiautos =(uiautos sasautos);
options sasautos
options nocenter;
options mprint nosymbolgen nomlogic;=i;
options msglevel%put Result=%ListChangeDelim( );
%put Result=%ListChangeDelim( a );
%put Result=%ListChangeDelim( a b );
%put Result=%ListChangeDelim( a b c d e f g );
%put Result=%ListChangeDelim( a b c d e f g, prefix=data. );
%put Result=%ListChangeDelim( a b c d e f g, new_delim=%str(, ) );
%put Result=%ListChangeDelim( %str(a,b,c,d,e,f,g), old_delim=%str(,), new_delim=%str( ) );
run;/**********************************************************************/
Change Deliminators
Purpose: Change delimiters in a macro variable list - default is change from spaces to commas. Optionally add prefix to list items.