hello team,
What is the difference between symputx and call symputx?
Respectfully,
blue&blue
Great question. This is a perfect place for you to consult the documentation.
https://documentation.sas.com/doc/en/pgmmvacdc/9.4/mcrolref/p1fa0ay5pzr9yun1mvqxv8ipzd4d.htm
The documentation has it description of the differences.
Comparisons
CALL SYMPUTX is similar to CALL SYMPUT. Here are the differences.
CALL SYMPUTX does not write a note to the SAS log when the second argument is numeric. CALL SYMPUT, however, writes a note to the log stating that numeric values were converted to character values.
CALL SYMPUTX uses a field width of up to 32 characters when it converts a numeric second argument to a character value. CALL SYMPUT uses a field width of up to 12 characters.
CALL SYMPUTX left-justifies both arguments and trims trailing blanks. CALL SYMPUT does not left-justify the arguments, and trims trailing blanks from the first argument only. Leading blanks in the value of name cause an error.
CALL SYMPUTX enables you to specify the symbol table in which to store the macro variable, whereas CALL SYMPUT does not.
But the main thing to remember is you only ever want to use the old (very old) CALL SYMPUT() function if it is required that the macro variable contain leading and/or trailing space characters.
I think I wish CALL SYMPUTX would throw the note about converting numeric values to character. I think I also wish the CAT functions would throw that note. It's fine, I guess, that SAS added routines / functions that will do implicit conversions, but it does seem NOTE-worthy to me.
See the article "Does SYMPUT work in IML" for a discussion about some of the points that @Quentin and others mention. Quentin: Note that not all SAS procedures do an automatic conversion. It is primarily the DATA step that decided to "be helpful" by performing automatic conversions.
When a function's name ends with an 'x' it strips leading and trailing blanks. For example, cat('a',' b ') = 'a b ', while catx('a',' b ') = 'ab'. Similarly, call symput("var", " MWSUG ") puts " MWSUG " into macro variable var, while call symputx("var", " MWSUG ") strips the leading and trailing blanks, putting "MWSUG" into macro variable var. The 'x' functions did not become available until version 9. The older way to strip the blanks was to nest the input parameters in a strip() function, so something like cat('a', strip(' b ')) would be equivalent to catx('a', ' b ').
@pink_poodle wrote:
(...) For example, cat('a',' b ') = 'a b ', while catx('a',' b ') = 'ab'. (...) something like cat('a', strip(' b ')) would be equivalent to catx('a', ' b ').
@pink_poodle: I think you mean cats, not catx.
catx('a',' b ') = 'b'
CATS concatenates the arguments; CATX uses the first argument as a delimiter between all the following arguments. Both functions remove leading and trailing blanks before concatenating.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.