@SivaKizildag wrote:
Hi. I have this MOIS variable (month), which I input as a number. But I need it to have a "0" in front from january to september (01 ... 09) and to have it as it (10 for october). I tried this code, but it doesnt seem to work, I still get 6 without the 0 in front when I need "06". Could you please help me ? Thanks!
%let mois=6;
%macro heyhey();
%if &mois<10 %then %let mois = %Sysfunc(Catx(%Str("0"),&mois));
%mend;
You do not need the CAT... series of data step functions to concatenate macro variables. To concatenate values in macro code all you have to do is type the values where you want them.
If you wanted to fix it with concatenation the code would just be:
%if &mois<10 %then %let mois = 0&mois;
The real fix is to use the Z format to make a macro variable that has the leading zeros.
%let mois = %sysfunc(putn(&mois,Z2.));
Plus the CAT... series of functions do not work well with %SYSFUNC() because they accept either numbers or characters as arguments and that means %SYSFUNC() has to try to figure out if your strings (everything in macro world is a string) look like numbers or not.
And you are also trying to use the wrong CAT... function. The first argument to the CATX() function is the string you want to insert between the other arguments. So you need to pass at least three arguments for it to do anything.
... View more