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;
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;
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.
Only add the double quotes to your string
data x;
call symput('currmon',put(intnx('MONTH',today(),0,'b'),yymmn6.));
cur="&currmon.";
run;
No Need to use intnx function
data x;
call symput('currmon',put(today(),yymmn6.));
cur="&currmon.";
run;
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)
I tried doing the same and it still gives me a numeric value of 201509.
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
.
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.
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.