DATA Step, Macro, Functions and more

translate function

Reply
Contributor
Posts: 40

translate function

%let aa="bddabc@new.dk"  "bddabc@new.dk";

%put &aa;

 

data new;

zz=translate("&aa","@","$");

run;

 

NOTE: Line generated by the macro variable "AA".

1    ""bddabc@new.dk"  "bddabc@new.dk"

     ---

     216

        -----

        388

        76

ERROR 216-185: The use of a BIT string constant is not allowed in this context.

 

ERROR 388-185: Expecting an arithmetic operator.

 

ERROR 76-322: Syntax error, statement will be ignored.

 

72   run;

 

Question : what does this error mean " The use of a BIT string constant is not allowed in this context."

 

Super User
Super User
Posts: 7,942

Re: translate function

Your error comes from having quotes in your macro variable:

%let aa="bddabc@new.dk"  "bddabc@new.dk";

 

Look at what is generated:

data new;

zz=translate(""bddabc@new.dk"  "bddabc@new.dk"","@","$");

run;

See the double quotes?

 

As always, I advise against putting lists of values in macro variables, data should go in datasets - clue is in the name.  And really don't put commas or quotes and things in macro variables at any time.

Contributor
Posts: 40

Re: translate function

Hello 

 

Actually values in macro variable  always will be in double quotes . I am working on some code which is working from long time and I cannot chnage that 

 

Should we have other solution rather than removing double quotes 

 

Thanks!!

Trusted Advisor
Posts: 1,555

Re: translate function

You can overcome the quotes problem by using sysmget function:

 

%let aa="bddabc@new.dk"  "bddabc@new.dk";

data _null_;
    aa = symget('aa');
    aa = translate(aa,'$','@');
    put aa=;
run;
Contributor
Posts: 40

Re: translate function

actually I am passing this value bddabc@new.dk" "bddabc@new.dk" as a postional parameter in the macro so I think I cannot use symget

Anyother way of passing this value
Trusted Advisor
Posts: 1,555

Re: translate function

You posted next code:

 

data new;

zz=translate("&aa","@","$");

run;

 

you need change one line:

 

data new;

zz=translate(symget("&aa"),"@","$");

run;

 

By the way, your macro variable &aa contains already @

if you want to translate it into $ you should write:

zz=translate(symget("&aa"),"$","@");

 

 

Ask a Question
Discussion stats
  • 5 replies
  • 257 views
  • 5 likes
  • 3 in conversation