DATA Step, Macro, Functions and more

using Catx in for combining TWO macro variables

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

using Catx in for combining TWO macro variables

Hi,

 I have my program as

 

%let date=26Jan2017;

%let time=0012;

 

%let dattt= %sysfunc(catx(T,&date,&time));

 

%put &dattt;

 

the value for &dattt is 26Jan2017T12,

But i want my value as 26Jan2017T0012,

Why im not getting 0012 for my time.

Please could any one help.


Accepted Solutions
Solution
‎01-11-2017 01:25 AM
Super User
Posts: 19,770

Re: using Catx in for combining TWO macro variables

Posted in reply to navyaroopa

Catx converts it to a number. Don't use it. 

 

 

%let datt=&date.T&time.;

 

View solution in original post


All Replies
Solution
‎01-11-2017 01:25 AM
Super User
Posts: 19,770

Re: using Catx in for combining TWO macro variables

Posted in reply to navyaroopa

Catx converts it to a number. Don't use it. 

 

 

%let datt=&date.T&time.;

 

Occasional Contributor
Posts: 5

Re: using Catx in for combining TWO macro variables

I have used  &date.T&time   as an alternative in the program, but wanted to know Why catx is not working. 

Super User
Posts: 19,770

Re: using Catx in for combining TWO macro variables

Posted in reply to navyaroopa

It thinks it's a number. Because the function takes char and num types either are valid and it has to guess at types in macro format. I don't know what the rules are, if you're really interested I would contact tech support. 

 

You may be able to force it in the SYSFUNC by including quotes around the value. 

 

 

Occasional Contributor
Posts: 5

Re: using Catx in for combining TWO macro variables

Hi Reeza,

 

I have given with the quotes as %let datt=%sysfunc(catx(T,"&date","&time"));

 

I am getting the value but along with the quotes.

 

I would be very Thankfull if you could consult  tech support and help me to know this.

 

Thank You.

Super User
Posts: 19,770

Re: using Catx in for combining TWO macro variables

Posted in reply to navyaroopa

Sorry, I meant to say you could contact tech support Smiley Happy 

 

 

PROC Star
Posts: 1,322

Re: using Catx in for combining TWO macro variables

Posted in reply to navyaroopa

Agree with @Reeza.  I don't see a way to tell CATX that the value that looks like a number is not a number.  And generally for concatenation in the macro language CAT functions are not needed, as shown in the accepted solution.

 

That said, if you went the route of adding quote marks, in the macro language those quote marks are part of the value (not a way to indicate that a value is text).  The good news is that when a quote mark (or any other non-numeric character) is part of the value, CATX will see that it is not a number.  But because those quote marks become part of the value, you would have to removed them yourself.

 

So in theory, you could hack it as something like:

40   %let date=26Jan2017;
41   %let time=0012;
42   %let datt=%sysfunc(compress(%sysfunc(catx(T,"&date","&time")),%str(%")));
43   %put &datt;
26Jan2017T0012
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 427 views
  • 0 likes
  • 3 in conversation