BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I am trying to replace a foreign character in a string, unfortunatelly most of useful string functions such as "tranwrd" does not work because SAS complains that it is not a valide SAS name. Right now, I created a macro. In the macro I get the length of the string, then use "substr" to get a single letter at a time, then do a cat afterwards.

Does anyone have a better idea please?

Thanks
Qun
11 REPLIES 11
Ksharp
Super User
options validvarname=any;
[pre]


Then you can use invalid sas varname.



Ksharp
[/pre]
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Share the actual SAS log with the specific error message revealed -- include all SAS program code revealed. You can do this with a COPY/PASTE into your next forum post-reply.

Also add this statement to generate additional diagnostic message with all variable values displayed to the log:

PUTLOG / _ALL_;

Scott Barry
SBBWorks, Inc. Message was edited by: sbb
deleted_user
Not applicable
Many thanks, Ksharp. I should've looked at the options in the first place.

Yan
data_null__
Jade | Level 19
It is unclear to me what you mean by foreign character. And if the characters are in variable values of variable names.

For values of variables check out COMPRESS.
Ksharp
Super User
Hi. _null_
For the foreign character, SAS has some specical function to process this situation.
For example : Kcompress()


Ksharp
deleted_user
Not applicable
I am confused as why the following code didn't work as I expected


options validvarname=any;

%macro test();
%global new;
%let old = ppø;
%let new = %sysfunc(tranwrd(&old, 'ø', 'aa'));
%put &new;
%mend;

%test();

%put &new;

The result is

MLOGIC(TEST): Beginning execution.
MLOGIC(TEST): %LET (variable name is NEW)
SYMBOLGEN: Macro variable OLD resolves to ppø
MLOGIC(TEST): %PUT &new
SYMBOLGEN: Macro variable NEW resolves to ppø
ppø
MLOGIC(TEST): Ending execution.
3832
3833 %put &new;
SYMBOLGEN: Macro variable NEW resolves to ppø
ppø


I would thought "new" should be "ppaa".


Many thanks,
Qun
deleted_user
Not applicable
Sorry, cut past the wrong code

options validvarname=any;

%let old=ppø;
%let new=&old;

%macro test();
%let new = %sysfunc(tranwrd(&old, 'ø', 'aa'));
%put &new;
%mend;

%test();

%put &new;
deleted_user
Not applicable
It's one of those issues with quote. Once I removed the quote around ø, and aa, it works.

I can never be sure when I suppose to ", or ' in data step or in macro.

Qun
Cynthia_sas
SAS Super FREQ
This is a good introduction to the SAS Macro facility:
http://www2.sas.com/proceedings/sugi28/056-28.pdf

cynthia
Ksharp
Super User
Hi.
_null_ is right .Macro facility treat anything as text ,even if it is the argument of function.


Ksharp
data_null__
Jade | Level 19
Don't use "quotes" 'quotes' in macro language.

1632 %let old=ppø;
1633 %let new=&old;
1634
1635 %let new = %sysfunc(tranwrd(&old, ø, aa));
1636 %put NOTE &new;
NOTE ppaa

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 1255 views
  • 0 likes
  • 5 in conversation