Created
January 19, 2021 00:42
-
-
Save statgeek/097840d38bdbb77dbaabd6f1ffec1d1e to your computer and use it in GitHub Desktop.
SAS - convert macro variable space delimited list to comma delimited
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*An example/demo of how to convert a macro variable list that is space delimited to comma delimited. | |
%Let weightvar = WEIGHT HEIGHT AGE; | |
*uses the translate function to replace spaces with commas. If VALIDVARNAME=ANY this may not work; | |
%macro addCommas(varList=); | |
%sysfunc(translate(&varList, %str(, ), %str( ))) | |
%mend addCommas; | |
*example recoding; | |
%let comma_delimited_list = %addCommas(varList = &weightvar); | |
%put &comma_delimited_list; | |
*example of in line usage within a procedure or data step; | |
data class; | |
set sashelp.class; | |
useless_variable = sum(%addCommas(varList = &weightVar.)); | |
run; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment