Thank you for the response.
Consider this:
4229 %let list1 = a b ;
4230 %let list2 = b c ;
4231
4232 data __dedup ;
4233 do var = "%sysfunc( prxchange( s/\s+/%str(" , ")/ , -1 , %nrbquote(&list1. &list2.)))" ;
4234 if var ne " " then put var= ;
4235 end ;
4236 run ;
var=a
var=b
var=b
var=c
NOTE: The data set WORK.__DEDUP has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
I am taking a list of SAS variables and quoting them and placing commas between them. A B will be "A" , "B". I already removed possible quotation marks (single and double) and commas. I need to mask the comma in the regex, so I used the %STR() function. I am protecting against a user submitting the same variable in both lists, so I de-dup it. I figured the SQL (or SORT) procedure has a trusted way, so I needed to put the variables as values of a variable in a SAS data set. This seemed like an obvious approach. This must be an issue with the macro compiler, since it works fine above.
If I were to use SAS code and not macro, then the quotation mark would "protect" the comma:
4344 data __dedup ;
4345 var = prxchange( 's/\s+/" , "/'
4346 , -1
4347 , "A B"
4348 ) ;
4349 put var= ;
4350 run ;
var=A" , "B
NOTE: The data set WORK.__DEDUP has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
This, also, was perplexing (at least from my level of understanding):
4250 %let list1 = %sysfunc( prxchange( s/\s+/%str(" , ")/ , -1 , %nrbquote(&list1.))) ;
4251 %put &list1. ;
a" , "b
4252
4253 %let list2 = %sysfunc( prxchange( s/\s+/%str(" , ")/ , -1 , %nrbquote(&list2.))) ;
NOTE: Line generated by the macro function "SYSFUNC".
1 b" , "c
-----
49
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space
between a quoted string and the succeeding identifier is recommended.
4254 %put &list2. ;
NOTE: Line generated by the macro variable "LIST2".
1 b" , "c
-----
49
b" , "c
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space
between a quoted string and the succeeding identifier is recommended.
Specifically, white space follows the double quotation mark; I purposefully inserted it. Quizzically, the first statement does not generate the code.
Kind regards,
Kevin
... View more