DATA Step, Macro, Functions and more

tRUE OR fALSE?

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,040
Accepted Solution

tRUE OR fALSE?

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


Accepted Solutions
Solution
‎10-29-2012 02:14 PM
PROC Star
Posts: 7,363

Re: tRUE OR fALSE?

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


All Replies
Solution
‎10-29-2012 02:14 PM
PROC Star
Posts: 7,363

Re: tRUE OR fALSE?

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))

Super Contributor
Posts: 1,040

Re: tRUE OR fALSE?

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

Super User
Super User
Posts: 6,499

Re: tRUE OR fALSE?

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. 

Super Contributor
Posts: 1,636

Re: tRUE OR fALSE?

Tom, How is Sandy doing in your area? 

Super User
Posts: 5,081

Re: tRUE OR fALSE?

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.

Super User
Posts: 9,676

Re: tRUE OR fALSE?

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

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 245 views
  • 6 likes
  • 6 in conversation