DATA Step, Macro, Functions and more

CALL SYMPUT vs CALL SYMPUTX

Accepted Solution Solved
Reply
Super Contributor
Posts: 279
Accepted Solution

CALL SYMPUT vs CALL SYMPUTX

I keep reading conflicting info.  Does CALL SYMPUTX automatically convert the value assigned to the macro variable to character (assuming it is numeric) or is the numeric format preserved?


Accepted Solutions
Solution
‎07-20-2017 02:20 PM
Super User
Posts: 5,498

Re: CALL SYMPUT vs CALL SYMPUTX

Both SYMPUT and SYMPUTX convert the value to character before assigning to a macro variable.

 

SYMPUT gives you a message on the log about the conversion, while SYMPUTX does not.

 

SYMPUTX takes the additional step of removing any leading blanks that were caused by the conversion.

View solution in original post


All Replies
Solution
‎07-20-2017 02:20 PM
Super User
Posts: 5,498

Re: CALL SYMPUT vs CALL SYMPUTX

Both SYMPUT and SYMPUTX convert the value to character before assigning to a macro variable.

 

SYMPUT gives you a message on the log about the conversion, while SYMPUTX does not.

 

SYMPUTX takes the additional step of removing any leading blanks that were caused by the conversion.

SAS Super FREQ
Posts: 3,752

Re: CALL SYMPUT vs CALL SYMPUTX

I assume you are asking about the DATA step? You can read about the differences between SYMPUT and SYMPUTX in the SAS doc.

 

According to the SAS documentation,  the DATA step will use BEST12. to convert the numeric value to a character value.

 

Not every SAS language does an automatic conversion, so SYMPUTX is more robust. See: http://blogs.sas.com/content/iml/2011/10/17/does-symput-work-in-iml.html

 

Super Contributor
Posts: 279

Re: CALL SYMPUT vs CALL SYMPUTX

yes, in the DATA step.

Super User
Super User
Posts: 7,039

Re: CALL SYMPUT vs CALL SYMPUTX

[ Edited ]

CALL SYMPUT() and CALL SYMPUTX() will convert numbers to text using BEST12. format.

If you want to preserve the format attached to a number then either convert it to character yourself or use the VVALUE() (or VVALUEX()) function to get the formatted value.

data _null_;
  x=123456.890123456;
  format x dollar12.2 ;
  call symputx('v1',x);
  call symputx('v2',put(x,best32.));
  call symputx('v3',vvalue(x));
  dt=date();
  format dt yymmdd10.;
  call symputx('d1',dt);
  call symputx('d2',put(dt,date9.));
  call symputx('d3',vvalue(dt));
run;
26  %put &=v1 &=v2 &=v3 &=d1 &=d2 &=d3;
V1=123456.89012 V2=123456.890123456 V3=$123,456.89 D1=21020 D2=20JUL2017 D3=2017-07-20
☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 1974 views
  • 8 likes
  • 4 in conversation