BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mgrasmussen
Quartz | Level 8

Dear SAS experts

 

I have made a simplified example of the problem I am facing.

 

Following the code in the bottom SAS reports:

 

SYMBOLGEN: Macro variable J resolves to 2008
SYMBOLGEN: Macro variable L resolves to 3
bef20083
SYMBOLGEN: Macro variable J resolves to 2008
SYMBOLGEN: Macro variable L resolves to 6
bef20086
SYMBOLGEN: Macro variable J resolves to 2008
SYMBOLGEN: Macro variable L resolves to 9
bef20089
SYMBOLGEN: Macro variable J resolves to 2008
SYMBOLGEN: Macro variable L resolves to 12
bef200812
SYMBOLGEN: Macro variable J resolves to 2009
SYMBOLGEN: Macro variable L resolves to 3
bef20093
SYMBOLGEN: Macro variable J resolves to 2009
SYMBOLGEN: Macro variable L resolves to 6
bef20096
SYMBOLGEN: Macro variable J resolves to 2009
SYMBOLGEN: Macro variable L resolves to 9
bef20099
SYMBOLGEN: Macro variable J resolves to 2009
SYMBOLGEN: Macro variable L resolves to 12

 

I would like to include a 0 in front of 3, 6 and 9, but it is not included based on my code. Can anyone help me resolve this issue.

 

Thank you

 

Here is the code:

 

%macro test;
 
%do j=2008 %to 2009 %by 1;
 
          %do l=3 %to 12 %by 3;
 
                    %if l<12 %then %do;
 
                    %put bef&j.0&l;
 
                     %end;
 
                     %else %do;
 
                     %put bef&j.&l;
 
                      %end;
 
          %end;
 
%end;
 
%mend;
 
%test;
1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @mgrasmussen,

 

Just insert the missing ampersand:

%if &l<12 %then %do;

 

View solution in original post

4 REPLIES 4
FreelanceReinh
Jade | Level 19

Hello @mgrasmussen,

 

Just insert the missing ampersand:

%if &l<12 %then %do;

 

FreelanceReinh
Jade | Level 19

You can also simplify the code by using SAS date values, the INTNX function and a date format:

%macro newtest;
%do i=0 %to 7;
  %put bef%sysfunc(intnx(qtr,'01JAN2008'd,&i,e),yymmn.);
%end;
%mend;
%newtest

 

PaigeMiller
Diamond | Level 26

@FreelanceReinh wrote:

You can also simplify the code by using SAS date values, the INTNX function and a date format:

%macro newtest;
%do i=0 %to 7;
  %put bef%sysfunc(intnx(qtr,'01JAN2008'd,&i,e),yymmn.);
%end;
%mend;
%newtest

 


@mgrasmussen this is an important point. You are always better off working with dates as actual valid numeric SAS dates as shown above by @FreelanceReinh, rather than working with them as text strings that have to be pulled apart, modified and combined somehow

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 259 views
  • 3 likes
  • 3 in conversation