BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8

Hi Team,

Scan is a macro function but Trim is not so is the difference in its usage!!

%let thisvar=%scan(&varnames,&ii,%str( ));

%let x=%sysfunc(trim(%sysfunc(left(&num))));

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Not sure what your question is.  scan is not a macro function, but %scan is.  %sysfunc is a macro function that lets us use SAS functions.  In your example, you asked about trim, but not about the similar 'left'.

Of course, you could replace the two with %sysfunc(strip(whatever))

View solution in original post

6 REPLIES 6
art297
Opal | Level 21

Not sure what your question is.  scan is not a macro function, but %scan is.  %sysfunc is a macro function that lets us use SAS functions.  In your example, you asked about trim, but not about the similar 'left'.

Of course, you could replace the two with %sysfunc(strip(whatever))

robertrao
Quartz | Level 8

Hi,

Thanks for the reply,

My question was why we could not go for:

%trim instead of  %sysfunc(trim(whatever) as we did for %scan???

Thanks

Tom
Super User Tom
Super User

Art already answered your question. Remember that macro code it just a tool to automate the generation of text that SAS can interpret as code. Trying to think of it as a real programming language will probably get you in trouble. 

Linlin
Lapis Lazuli | Level 10

Tom, How is Sandy doing in your area? 

Astounding
PROC Star

As you have found, most functions just don't exist in macro language.  That's why %sysfunc was invented, to allow other functions to be called by macro language.  Also note, if your objective is to strip leading and trailing blanks from a macro variable, you don't need a function to do it:

%let a = &a;

The %let statement will ignore the leading and trailing blanks to the right of the equal sign.

Good luck.

Ksharp
Super User

There are already some built-in macro function, include TRIM and LEFT .

%let x=%trim(%left(whatever));

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 1257 views
  • 6 likes
  • 6 in conversation