BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ncvol82
Calcite | Level 5

The code below  works fine.  The output file is the same as the input with 'TBL_' added as a name prefix.  However, when I try to append  '_TBL' as a suffix,  rather than prefix, the step fails thinking that the '_TBL' is part of the macro variable name. 

 

 

%MACRO PREP_TBL;

%DO I = 1 %TO 3 ;
DATA TBL_&&TBL&i|' ;
SET &&TBL&i ;
WHERE DATE_ID GE 20160701 AND DATE_ID LE 20180630 ;
RUN;
%END ;

 

%PREP_TBL ;

%MEND;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
DATA &&TBL&i.._TBL ;

Use two dots to end a macro variable reference that begins with &&

--
Paige Miller

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

Show us the code that doesn't work.

--
Paige Miller
ncvol82
Calcite | Level 5

%MACRO PREP_TBL;
34
35 %DO I = 1 %TO 1 ;
36 DATA &&TBL&i._TBL ;
37 SET &&TBL&i ;
38 WHERE DATE_ID GE 20160701 AND DATE_ID LE 20180630 ;
39 TRAN_DT = INPUT(PUT(DATE_ID,Z8.),YYMMDD8.) ;
40 TRAN_DYOFWK = WEEKDAY(TRAN_DT) ;
41 TRAN_REMDAYS = 7 - TRAN_DYOFWK ;
42 TRAN_WKEND = TRAN_DT + (TRAN_REMDAYS) ;
43 FORMAT TRAN_DT TRAN_WKEND MMDDYY10. ;
44 DROP TRAN_REMDAYS TRAN_DYOFWK ;
45 RUN;
46 %END ;
47
48 proc sort ;
49 by LOAN_ID TRAN_WKEND TRAN_DT ;
50 run;
51
52 %MEND;
53
54 %PREP_TBL;
MLOGIC(PREP_TBL): Beginning execution.
MLOGIC(PREP_TBL): %DO loop beginning; index variable I; start value is 1; stop value is 1; by value is 1.
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable I resolves to 1
WARNING: Apparent symbolic reference TBL1_TBL not resolved.

PaigeMiller
Diamond | Level 26
DATA &&TBL&i.._TBL ;

Use two dots to end a macro variable reference that begins with &&

--
Paige Miller
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

You may also need the double dots on this line

SET &&TBL..&i ;

Tom
Super User Tom
Super User

You can fix it with making sure you tell SAS where your macro variable reference ends.

But why bother.  Just take the time to write out the steps and neither SAS nor you will get confused about what you are trying to do.

%macro prep_tbl;
%local i in out;
%do i = 1 %to 1 ;
  %let in=&&tbl&i;
  %let out=&in._tbl;

data &out;
  set ∈
  where date_id ge 20160701 and date_id le 20180630 ;
  tran_dt = input(put(date_id,z8.),yymmdd8.) ;
  tran_dyofwk = weekday(tran_dt) ;
  tran_remdays = 7 - tran_dyofwk ;
  tran_wkend = tran_dt + (tran_remdays) ;
  format tran_dt tran_wkend mmddyy10. ;
  drop tran_remdays tran_dyofwk ;
run;

%end ;

%mend prep_tbl;
ncvol82
Calcite | Level 5

The two dots worked.  Thanks.

Kurt_Bremser
Super User

@ncvol82 wrote:

The code below  works fine.  The output file is the same as the input with 'TBL_' added as a name prefix.  However, when I try to append  '_TBL' as a suffix,  rather than prefix, the step fails thinking that the '_TBL' is part of the macro variable name. 

 

 

%MACRO PREP_TBL;

%DO I = 1 %TO 3 ;
DATA TBL_&&TBL&i|' ;
SET &&TBL&i ;
WHERE DATE_ID GE 20160701 AND DATE_ID LE 20180630 ;
RUN;
%END ;

 

%PREP_TBL ;

%MEND;


This code cannot work, as the pipe character and a single quote are not allowed in SAS names.

You also have a data design problem, as you seem to store dates as funny numbers and not as SAS date values.

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
  • 7 replies
  • 4134 views
  • 1 like
  • 5 in conversation