- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Instead of using translate to check for every possible illegal character that might appear, as originally proposed, how about using translate to change only the illegal characters that actually do appear? For example:
[pre]
37 data _null_;
38 length valid_name $ 32;
39 string = 'ABC(#)DEF';
40 valid_name = translate(string, repeat('_', 50), compress(string,'_', 'adi'));
41 if anydigit(valid_name)=1 then valid_name = '_'!!valid_name;
42 put valid_name=;
43 run;
valid_name=ABC___DEF
[/pre]
[pre]
37 data _null_;
38 length valid_name $ 32;
39 string = 'ABC(#)DEF';
40 valid_name = translate(string, repeat('_', 50), compress(string,'_', 'adi'));
41 if anydigit(valid_name)=1 then valid_name = '_'!!valid_name;
42 put valid_name=;
43 run;
valid_name=ABC___DEF
[/pre]
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Recently, I met the same problem, here is my solution:
%macro correct_sas_name(name);
%let flag=%sysfunc(notname(&name));
%do %until(&flag=0);
%let char=%substr(&name,&flag,1);
%let name=%sysfunc(TRANWRD(&name,&char,_));
%let flag=%sysfunc(notname(&name));
%end;
h_&name
%mend;
%let test=SAS#123!34;
%let correct_name=%correct_sas_name(&test);
%put &test;
%put &correct_name;
The LOG:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Have a look at the function nliteral : Converts a character string that you specify to a SAS name literal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This is good way, thanks.
But, normally this way is not that common.
- « Previous
-
- 1
- 2
- Next »