Raffaele
Raffaele

Reputation: 133

How to use SYSFUNCT and PUTC or PUTN

In a macro I have 2 variables, A and B. A is a cycle variable and is an integer from 1 to 12. B needs to be 01 when A is 1, 02 when A is 2, etc, 10 when A is 10, 11 when A is 11 and 12 when A is 12. Basically B needs to be 2 digits, possibly with leading zeros. In a datastep this is easy:

B=PUT(A,z2.);

But inside a macro this code will not work and SYSFUNC will not work with PUT function. So how can the job be done?

Upvotes: 1

Views: 6125

Answers (1)

Joe
Joe

Reputation: 63424

putn works fine. putc is for incoming char arguments ($ formats), putn is for incoming numeric arguments like this one.

%let a=5;
%let b=%sysfunc(putn(&a,z2.));
%put &=a. &=b.;

Upvotes: 1

Related Questions