Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

format macro variable to comma6

Tags:

format

sas

%let vc = 12025;

ideal output (with format comma ) is 12,025;

but %put %sysfunc(put(&vc,comma6.)) seems not working. Error as below.

ERROR: The PUT function referenced in the %SYSFUNC or %QSYSFUNC macro function is not found.

like image 794
Lovnlust Avatar asked Jun 08 '26 14:06

Lovnlust


2 Answers

The PUT function is not available with %SYSFUNC, however you can use PUTN for numeric values, or PUTC for character.

Try :

%put %sysfunc(putn(&vc,comma6.));
like image 131
Longfish Avatar answered Jun 10 '26 08:06

Longfish


An alternative to using the putn() function to format values returned by %sysfunc() is to use the little known 2nd parameter of %sysfunc() like so:

%let vc = 12025;
%put %sysfunc(sum(&vc),comma6.);

The second argument applies a format to the result returned by whatever function %sysfunc() is calling. In the above example, I'm just summing a number by itself which effectively just returns the number. If it was a character value, I could use the cats() function.

Worth noting as it will simplify code if you want to do something like:

%put %sysfunc(putn(%sysfunc(date()),date9.));    

as it becomes:

%put %sysfunc(date(),date9.);
like image 39
Robert Penridge Avatar answered Jun 10 '26 09:06

Robert Penridge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!