Desktop productivity for business analysts and programmers

%trim function

Reply
N/A
Posts: 0

%trim function

Hi
i have to remove the leading and trailing space in the value of macro variable.
i am working in SAS DI studio.
i have tried %trim()....it is not working ...whereas it is working fine in Base SAS.


please i need help...
Respected Advisor
Posts: 4,132

Re: %trim function

Hi

You're always using "Base SAS" no matter how you execute the code.

If this is a macro variable created in a autoexec then there might be a difference between a SAS DI session (like SAS EG created by the Object Spawner) and a PC SAS session - and you might not have fully access to this macro var from within the session (as soon as you batch the job you will have full access).

I can be wrong here but I think that strings assigned to macro vars are always stripped of leading and trailing blanks.

What could be is that you're string is quoted - and an %unquote() could solve the problem.

Have a look at the following example:
%let TESTVAR1= xxx y ;
%put TESTVAR1 unquoted: Length is: %length(&TESTVAR1), Value is: &TESTVAR1;

%let TESTVAR2=%quote( xxx y );
%put TESTVAR2 quoted: Length is: %length(&TESTVAR2), Value is: &TESTVAR2;

%let TESTVAR3=%quote( xxx y );
%let TESTVAR3=%trim(&TESTVAR3);
%put TESTVAR3 quoted/trim: Length is: %length(&TESTVAR3), Value is: &TESTVAR3;

%let TESTVAR4=%quote( xxx y );
%let TESTVAR4=%unquote(&TESTVAR4);
%put TESTVAR4 quoted/unquoted: Length is: %length(&TESTVAR4), Value is: &TESTVAR4;
Ask a Question
Discussion stats
  • 1 reply
  • 200 views
  • 0 likes
  • 2 in conversation