BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sfmeier
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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

View solution in original post

5 REPLIES 5
Astounding
PROC Star

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.

sfmeier
Obsidian | Level 7

I tried exactly that, but it does not work 😞

Astounding
PROC Star

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));

data_null__
Jade | Level 19

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

sfmeier
Obsidian | Level 7

Ok, cool, thx! It works perfectly without catx... 🙂

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 13651 views
  • 1 like
  • 3 in conversation