BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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...
1 REPLY 1
Patrick
Opal | Level 21
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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1360 views
  • 0 likes
  • 2 in conversation