DATA Step, Macro, Functions and more

numeric to char

Reply
Frequent Contributor
Posts: 87

numeric to char

Hi,

 

I've below macro that is creating 201509 value as numeric. I need it as a character value. Please suggest.

 

data x;

call symput('currmon',put(intnx('MONTH',today(),0,'b'),yymmn6.));

cur=&currmon.;

run;

 

Super User
Posts: 10,044

Re: numeric to char

In the same data step ?

cur=symgetn('currmon') ;
Super User
Posts: 3,260

Re: numeric to char

Your code is using a DATA step function to write to a macro variable then trying to write the macro variable back to a SAS variable.

 

Why not just do it directly?

 

data x;

  cur = put(intnx('MONTH',today(),0,'b'),yymmn6.);

run;

Frequent Contributor
Posts: 87

Re: numeric to char

My bad guys, Thanks for your response. I'm not trying to write the value back to variable. I just did that to see if the macro variable is resolving as a numeric or character. 

New Contributor
Posts: 4

Re: numeric to char

Only add the double quotes to your string

 

data x;

call symput('currmon',put(intnx('MONTH',today(),0,'b'),yymmn6.));

cur="&currmon.";

run;

New Contributor
Posts: 4

Re: numeric to char

Posted in reply to surajdvpatil

No Need to use intnx function

 

data x;
call symput('currmon',put(today(),yymmn6.));
cur="&currmon.";
run;

Super User
Posts: 7,859

Re: numeric to char

Posted in reply to surajdvpatil

Both of your tips won't work because the macro variable in the cur= assigment will be evaluated (during data step compilation) before it is set with the call symput (during data step execution)

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Frequent Contributor
Posts: 87

Re: numeric to char

Posted in reply to surajdvpatil

I tried doing the same and it still gives me a numeric value of 201509. 

SAS Employee
Posts: 12

Re: numeric to char

[ Edited ]

All macro variables are stored as strings.  What behavour (error message etc) are you seeing that makes it numeric.

http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a002293823.htm

 

You can see from this log that if we try to store a numeric in a macro var it is converted to char by SAS.

 

1 data null;
2 call symput('currmonS',put(date(),yymmn6.));
3 call symput('currmonN',date());
4 run;
NOTE: Numeric values have been converted to character values at the places given by:
(Line) : (Column).
3:28

NOTE: The data set WORK.NULL has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

.

Ask a Question
Discussion stats
  • 8 replies
  • 284 views
  • 2 likes
  • 6 in conversation