In a macro I am using the code
------------------------------
%SYSFUNC(catx(_,&number ,%SYSFUNC(Intnx(qtr, &dvar, 0, end), DDMMYYP10.)))
-----------------------------
to create the output
-----------------------------
5_30.06.2013
-----------------------------
How can I create a dynamic leading zero?
Looks like CATX is treating the number like a number. You don't need CATX.
405 %let number=5;
406 %let dvar=%sysfunc(today());
407 %PUT NOTE: %sysfunc(putN(&number,z2))_%SYSFUNC(Intnx(qtr, &dvar, 0, end), DDMMYYP10.);
NOTE: 05_30.06.2012
Try replacing &number with:
%sysfunc(putn(&number, z2))
Messy, but it should work.
This assumes that &number is always less than 100, and you only want a leading zero when &number < 10.
I tried exactly that, but it does not work 😞
OK, you actually made me test my code. It does work for me. There are subtle parts of the syntax, such as PUTN instead of PUT, and no period at the end of the format name. Can you post what you coded, and the results?
This is what worked:
%let n=5;
%let newn = %sysfunc(putn(&n, z2));
Looks like CATX is treating the number like a number. You don't need CATX.
405 %let number=5;
406 %let dvar=%sysfunc(today());
407 %PUT NOTE: %sysfunc(putN(&number,z2))_%SYSFUNC(Intnx(qtr, &dvar, 0, end), DDMMYYP10.);
NOTE: 05_30.06.2012
Ok, cool, thx! It works perfectly without catx... 🙂
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.