BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Aniruddhaanu
Fluorite | Level 6
Data _null_
Call symput ('Month',put(intnx('month',today(),-2,'B'),monname.));
%put &month1. "22
While resolving macro variable month1 i want "22 ( single quite and 22 ) at the end of macro variable how i can add ?
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

You have already got the desired result. Just add %nrbquote() to mask the single quote.

 

Data _null_;
Call symput ('Month1',put(intnx('month',today(),-2,'B'),monname.));
stop;
run;
%put %nrbquote( &month1. '22 ) ;

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26

Could you please fix the syntax errors in your code, which does not run at all.

 

It seems as if you are creating a month name, but then you say

 

While resolving macro variable month1 i want "22 ( single quite and 22 ) at the end of macro variable how i can add ?

 

and this doesn't make sense to me as a month name will never yield "22 when a quote is put in front of the month name.

--
Paige Miller
Aniruddhaanu
Fluorite | Level 6
Actually I want in mail that ,this is data of May"22.

I have checked no syntax error there.
Even i can Abe to create May_22 variable but unable to create May"22

Kurt_Bremser
Super User

@Aniruddhaanu wrote:
Actually I want in mail that ,this is data of May"22.


Do it in the data step that writes the mail:

proc format;
picture mydate
  low-high = '%b"%0y' (datatype=date)
;
run;

data _null_;
var = put(intnx('month',today(),-2,'B'),mydate.);
put "This is data of " var;
run;

This way you avoid that the quote will ever appear in the code instead of just in data.

PaigeMiller
Diamond | Level 26

@Aniruddhaanu wrote:
Actually I want in mail that ,this is data of May"22.

I have checked no syntax error there.
Even i can Abe to create May_22 variable but unable to create May"22


Your code, plus a RUN; statement

 

Data _null_
Call symput ('Month',put(intnx('month',today(),-2,'B'),monname.));
run;

LOG

 

1036  Data _null_
1037  Call symput ('Month',put(intnx('month',today(),-2,'B'),monname.));
                   -------                                  -
                   22                                       22
                                                            200
ERROR 22-7: Invalid option name 'Month'.

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, /, ;, _DATA_, _LAST_, _NULL_.

ERROR 200-322: The symbol is not recognized and will be ignored.

1037! Call symput ('Month',put(intnx('month',today(),-2,'B'),monname.));
                                                    -
                                                    22
ERROR 22-7: Invalid option name ,.

1038  run;

NOTE: Compression was disabled for data set WORK.CALL because compression overhead would increase the size of the data set.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.CALL may be incomplete.  When this step was stopped there were 0 observations and 0 variables.
WARNING: Data set WORK.CALL was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds

Please provide code without syntax errors from now on.

--
Paige Miller
Kurt_Bremser
Super User

Quotes (especially unbalanced quotes) are VERY dangerous in macro variables, as they will always trick the SAS interpreter into thinking that the string goes on and on, unless you are EXTREMELY diligent in using tools to mask the quote.

 

What do you try to do with this macro variable later on?

Kurt_Bremser
Super User

You can create a format that automatically includes the quote and year:

proc format;
picture mydate
  low-high = '%b"%0y' (datatype=date)
;
run;

data _null_;
call symput ('Month',put(intnx('month',today(),-2,'B'),mydate.));
run;

or you add the quote in the original step:

call symput ('Month',put(intnx('month',today(),-2,'B'),monname.)!!'"22');
Aniruddhaanu
Fluorite | Level 6
Getting ,error:open code statement recursion detected
Kurt_Bremser
Super User

@Aniruddhaanu wrote:
Getting ,error:open code statement recursion detected

My code does not have a single element which could cause this message, it is tested. Start a new session and run my code, nothing else.

If you run additional code, post your complete log.

Ksharp
Super User

You have already got the desired result. Just add %nrbquote() to mask the single quote.

 

Data _null_;
Call symput ('Month1',put(intnx('month',today(),-2,'B'),monname.));
stop;
run;
%put %nrbquote( &month1. '22 ) ;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 9 replies
  • 1051 views
  • 2 likes
  • 4 in conversation