How about this?
%let DRGFilterCommas=1,2,3;
data _null_;
length DRGCommas_List $10000;
DRGCommas_List=cats("'", tranwrd("&DRGFilterCommas", ",", "','"), "'");
put DRGCommas_List; /* just for checking */
run;
Try adding
comma= "','";
and use the variable instead of "','"; Too many quotes.
I suspect that it might be easier to use a space separated list unless you are using this in multiple different contexts.
data example;
x = '1 2 3 4 5';
length DRGCommas_temp $ 125;
DRGCommas_temp='';
do i= 1 to (countw(x));
DRGCommas_temp= catx(',',DRGCommas_temp,quote(scan(x,i)));
end;
run;
Thanks ballardw. I can't delimit with a space because the values could have spaces in them , for example, Joe Smith, Suzie Jones. etc.
I tried to substitute the comma as you suggested and got the same error unfortunately.
data _null_;
length DRGsCommas_List $10000;
/*Replace comma with single quote comma single quote and then concatenate single quote at beginning and end of list of DRGs*/
comma = ",";
DRGCommas_temp=tranwrd(&DRGFilterCommas,comma,'comma');
DRGCommas_List=cat("'",trim(DRGCommas_temp),"'");
run;
ERROR 72-185: The TRANWRD function call has too many arguments.
SCAN and COUNTW allow specifying the delimiter.
data example;
x = 'Sue Jones, Fred Smith, Billy Bog';
length DRGCommas_temp $ 1250;
DRGCommas_temp='';
do i= 1 to (countw(x,','));
DRGCommas_temp= catx(',',DRGCommas_temp,quote(scan(x,i,',')));
end;
run;
Thanks ballardw. I will check this way out also. I received a solution from another post, but I will check this method out as well.
How about this?
%let DRGFilterCommas=1,2,3;
data _null_;
length DRGCommas_List $10000;
DRGCommas_List=cats("'", tranwrd("&DRGFilterCommas", ",", "','"), "'");
put DRGCommas_List; /* just for checking */
run;
That works FreelanceReinhard. Thank you so much!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.