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

Hello All, I've created the macro below,  however when I run the very first SQL statement of my code I keep getting errors??

Macro below:

%MACRO NEEDDT(PLM12019,BEGDATE,ENDDATE);
%LET BEGDATE = MDY(12,31,2019);
%LET ENDDATE = MDY(01,31,2020);
%LET CYABSTR =PLM12020; /*use if pulling from a ASQ abstract*/
%LET PRABSTR =PLM12019;
%MEND NEEDDT;

 

My first SQL statement below:

PROC SQL; create table r.originalPLMPOP as select
PLDOCNUM AS CIDORNUM LABEL='CIDORNUM'
FROM &PRABSTR
WHERE EVNTTYPE='07'; /*Prison Population*/
QUIT;

 

Errors below:

PROC SQL;
10 ! create table r.originalPLMPOP as select
11 PLDOCNUM AS CIDORNUM LABEL='CIDORNUM'
12 FROM &PRABSTR
WARNING: Apparent symbolic reference PRABSTR not resolved.
12 FROM &PRABSTR
-
22
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (,
CONNECTION, DICTIONARY.

12 FROM &PRABSTR
-
200
ERROR 200-322: The symbol is not recognized and will be ignored.

13 WHERE EVNTTYPE='07';
13 ! /*Prison Population*/
14 QUIT;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.03 seconds
cpu time 0.01 seconds

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

&PRABSTR has not been defined in the current scope where SQL is running. You probably need to learn about macro scopes.

 

When you define &PRABSTR inside the macro named %NEEDDT, then &PRABSTR does not exist outside of that macro. There are two way to get around this. The easiest is to not define &PRABSTR inside %NEEDDT, define &PRAVSTR outside of a macro, and then it is consider Global and can be accessed anywhere in your program.

 

By the way, your macro %NEEDDT as shown, doesn't seem to be needed, as all of the  commands in that macro can be (and should be) issued outside of a macro.

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

&PRABSTR has not been defined in the current scope where SQL is running. You probably need to learn about macro scopes.

 

When you define &PRABSTR inside the macro named %NEEDDT, then &PRABSTR does not exist outside of that macro. There are two way to get around this. The easiest is to not define &PRABSTR inside %NEEDDT, define &PRAVSTR outside of a macro, and then it is consider Global and can be accessed anywhere in your program.

 

By the way, your macro %NEEDDT as shown, doesn't seem to be needed, as all of the  commands in that macro can be (and should be) issued outside of a macro.

--
Paige Miller
Renee1984
Calcite | Level 5

Thank you very much, this worked perfectly...making it global!! Problem Solved

Tom
Super User Tom
Super User

You don't show any code that is using that macro.  If you want to use the value it is assigning to PRABSTR after it ends make sure that PRABSTR exists before you call the macro.

 

 

%let PRABSTR=;
%let BEGDATE=;
%let ENDDATE=;
%NEEDDT;

 

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
  • 3 replies
  • 555 views
  • 2 likes
  • 3 in conversation