DATA Step, Macro, Functions and more

why trim when use symput

Accepted Solution Solved
Reply
Super Contributor
Posts: 336
Accepted Solution

why trim when use symput

DATA _null_; Threshold=250000; call symput('u_Threshold',trim(Threshold)); RUN;

 

Please see above code. I do not understand, since threshold is already hard coded, I do not know why there is the need for trim(thresold).

Anyone gives me the exaplanation?

And what if I replace this with symputx?

Thank you

 


Accepted Solutions
Solution
‎05-03-2017 02:30 PM
Super User
Posts: 5,071

Re: why trim when use symput

You cannot use PUT.  You must use %PUT.  Then you will see 12 characters appear between the two asterisks.

 

Yes, if you use SYMPUTX you do not need TRIM (or STRIP or LEFT or COMPRESS) ... all leading and trailing blanks will be gone.  You can see that in the same way (with %PUT).

View solution in original post


All Replies
Super User
Posts: 5,071

Re: why trim when use symput

If you were to examine the value of &U_THRESHOLD, you would find it contains 12 characters:   6 blanks followed by 6 digits.  You can see this easily using:

 

%put *&u_threshold*;

 

Since there are no trailing blanks, TRIM would not affect the result.  However, STRIP would remove both leading and trailing blanks, and would make a difference.

 

The extra blanks get added because the second parameter to CALL SYMPUT is supposed to be a character string.  When a numeric is supplied, it forces SAS to make a numeric-to-character conversion.  You can see that this took place, by reading the log.

 

CALL SYMPUTX would make a difference.  Although it still must perform the numeric-to-character conversion, it also removes the leading blanks that result.  &U_THRESHOLD would be only 6 characters long.  Also, the note in the log about numeric-to-character conversion would disappear when using CALL SYMPUTX.

Super Contributor
Posts: 336

Re: why trim when use symput

Can you explain?

Do you mean, when I type, "put *&u_threshold*;" I can see it contains 12 characters?

Do you mean, if I use CALL SYMPUTX , I do not need to use "Trim"

Solution
‎05-03-2017 02:30 PM
Super User
Posts: 5,071

Re: why trim when use symput

You cannot use PUT.  You must use %PUT.  Then you will see 12 characters appear between the two asterisks.

 

Yes, if you use SYMPUTX you do not need TRIM (or STRIP or LEFT or COMPRESS) ... all leading and trailing blanks will be gone.  You can see that in the same way (with %PUT).

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 125 views
  • 1 like
  • 2 in conversation