Symput and Symget

Reply
Occasional Contributor
Posts: 8

Symput and Symget

Hi All,

 

Can anyone please explain me the exact difference between Symput and Symget functions in macro with example.

 

Thanks and Regards,

Ankita Roy

Esteemed Advisor
Esteemed Advisor
Posts: 7,232

Re: Symput and Symget

Hi,

 

Symput -> puts the character string into the macro symbol table

Symget -> gets the character srting from the macro symbol table

data _null_;
   call symput('MVAR',"This is a macro variable character string");
run;
data want;
  avar=symget('MVAR');
run;

 

SAS Super FREQ
Posts: 3,415

Re: Symput and Symget

In addition to @RW9's response, I'll add that SYMPUT technically puts a character value into a macro variable.  If you want to create a macro that contains a number, use the SYMPUTX call, which the automatically converts the number (the second argument). See my blog for an example and explanation.

Esteemed Advisor
Esteemed Advisor
Posts: 7,232

Re: Symput and Symget

Just to note on that @Rick_SAS, even if you use symputx() the result is still a character string.  Macro only has string datatype (in fact its not even a datatype eveything is string).  Whilst symputx() converts the number do be aware that:

---

specifies a character or numeric constant, variable, or expression. If value is numeric, SAS converts the value to a character string using the BEST. format and does not issue a note to the SAS log. Leading and trailing blanks are removed, and the resulting character string is assigned to the macro variable.

---

This means that the resulting text string may not be what you want, I would always advise put()'ing the numeric variable into the format you want rather than letting SAS guess.

SAS Super FREQ
Posts: 3,415

Re: Symput and Symget

[ Edited ]

Yes. All macro variables are character values that get substituted into programs when the SAS pre-processor runs. That is spelled out explicitly in the blog post that I linked to.

Ask a Question
Discussion stats
  • 4 replies
  • 328 views
  • 1 like
  • 3 in conversation