BookmarkSubscribeRSS Feed
GN0001
Barite | Level 11

hello team,

What is the difference between symputx and call symputx?

 

Respectfully,

blue&blue

Blue Blue
9 REPLIES 9
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
Tom
Super User Tom
Super User

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.

Quentin
Super User

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.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Bart Jablonski and I present 53 (+3) ways to do a table lookup on Wednesday Sep 18.
Register now at https://www.basug.org/events.
Rick_SAS
SAS Super FREQ

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. 

pink_poodle
Barite | Level 11

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

FreelanceReinh
Jade | Level 19

@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'
pink_poodle
Barite | Level 11
I see, there is also CATS. CATS is kind of like CATX. Now what is the difference between CATS and CATX...
https://documentation.sas.com/doc/en/vdmmlcdc/1.0/lefunctionsref/n0p7wxtk0hvn83n1pveisbcp2ae9.htm
Quentin
Super User
There's a whole family of CAT functions. I always thought the x in CATX meant "insert some value, X, as a delimiter between items." As opposed to just stripping items (CATS) or trimming (CATT). Louise Hadden wrote a great paper on CAT functions: https://www.lexjansen.com/nesug/nesug09/po/PO05.pdf .

I never had a theory for any 'meaning' for the x on the end of CALL SYMPUTX. I feel like they didn't want to call it CALL SYMPUT2, but they also sensibly couldn't change CALL SYMPUT without breaking legacy code, and then just decided to put an X on the end to give it a different name.
The Boston Area SAS Users Group is hosting free webinars!
Next up: Bart Jablonski and I present 53 (+3) ways to do a table lookup on Wednesday Sep 18.
Register now at https://www.basug.org/events.
Kurt_Bremser
Super User

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.

SAS Innovate 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 9 replies
  • 1928 views
  • 19 likes
  • 8 in conversation