BookmarkSubscribeRSS Feed
helloSAS
Obsidian | Level 7

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;

 

8 REPLIES 8
Ksharp
Super User
In the same data step ?

cur=symgetn('currmon') ;
SASKiwi
PROC Star

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;

helloSAS
Obsidian | Level 7

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. 

surajdvpatil
Calcite | Level 5

Only add the double quotes to your string

 

data x;

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

cur="&currmon.";

run;

surajdvpatil
Calcite | Level 5

No Need to use intnx function

 

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

Kurt_Bremser
Super User

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)

helloSAS
Obsidian | Level 7

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

ChrisWard
SAS Employee

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

.

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
  • 8 replies
  • 1327 views
  • 2 likes
  • 6 in conversation