BookmarkSubscribeRSS Feed
cbrotz
Pyrite | Level 9

I need to create prompts in a SAS EG project to help others use this data.  The alpha data works just fine with a prompt. I have one YEAR field though that works, but when I close my EG session and open it back up, it errors out. If I re-create the macro variable and prompt, it will work again. I could change the year to be alpha for the prompt but am curious why the numeric prompt will not stick. Below is the error I am getting at times.  Thanks for taking a look.

 

cbrotz_0-1648065960796.png

 

10 REPLIES 10
Tom
Super User Tom
Super User

The code you posted does not appear to have anything to do with prompts or character versus numeric.

The error message is about referencing a macro variable that does not exist.  Your code is trying to reference a macro variable named YEAR_19_21.   If you want to reference a macro variable named year then insert a period to let the macro processor know where the name of the macro variable ends. 

 &YEAR._19_21

Once you fix that then you need to deal with the issue of what types of values the YEAR macro variable might contain.  For a expression like this to work:

where year=&YEAR._19_21

The macro variable YEAR would need to (1) Start with a letter or an underscore (2) only include underscores letters and digits (3) When the value _19_21 is appended to its contents the result is the name of variable that exists.

cbrotz
Pyrite | Level 9

These are the prompts I created using the Prompt Manager.  

cbrotz_0-1648068876909.png

The first three are text and the last two are numeric.  I am using the prompt input in my code below.

WHERE ORG_NAME="&ORG_NAME" and YEAR=&YEAR_19_21;

ORG_NAME gives the correct output using the prompt input.  Year, or year_19_21 does not.  I also created a prompt called YEAR.  I copied this from another example, so yes my syntax could be wrong.  The code does work for text. I do not see any examples for a numeric prompt so there must be a difference that I am not aware of.

 

 

ballardw
Super User

What is the exact value that the &Year_19_21 was supposed to have and use?

 

The error message tells you a lot about the problem but I am not going to retype the error message. About the only thing your variable &Year_19_21 can be is something character that is used incorrectly as the message says it is not a number.

 

 

 

Hint: do not cut up bits of log and best is to copy the text of an entire procedure or data step with all the notes, messages, warnings or errors from the log; open a text box on the forum with the </> icon that appears above the message window and then paste. Sometimes errors are caused by problems quite a ways back in the code and the syntax checkers don't see a problem until much later.

 

It is ever so much easier for us to copy stuff, like names of variables or blocks of code text and make suggestions/corrections/ or point out things that are just plain not possible, or take 100 times as long, dealing with pictures of code.

cbrotz
Pyrite | Level 9

The user needs to enter a year or years - 2019 through 2021. 

 

PROC SQL;
CREATE TABLE WORK.DATA_BY_YEAR AS
SELECT t1.ORGGROUP,
t1.ACCOUNT_ID,
t1.ACTIVE_FLAG,
t1.ORG_NAME,
t1.YEAR,
t1.GOAL_TYPE,
t1.ABC_PL,
t1.DOLLARS
FROM SASDATA.CUST_PROFILE_CMB_DATA t1
WHERE YEAR=&YEAR.;
QUIT;

 

I added the . after the macro name and this time it worked.

 

cbrotz_0-1648071676815.png

but so did this code....If I shut down this project and re-open, I will get errors - like it needs time to connect  or something.  Weird.

 

cbrotz_1-1648071776414.png

 

 

ballardw
Super User

...If I shut down this project and re-open, I will get errors - like it needs time to connect or something. Weird.

 

Are you assuming that the entered prompt value is supposed to exist in the next session you run?

I don't believe that is how prompts work. They should be entered in each session. That's part of why they are called "prompts". The coder has a user enter enter a value the user is wants to use. If nothing is entered at the prompt then the value is missing, resulting in the types of errors you are talking about.

cbrotz
Pyrite | Level 9

No. Every time I run the code it requires new input.  Just that the input seems to work after the session is open for a certain amount of time for the numeric prompt to be recognized.  I am not having that issue with the text prompts. I just added a new variable with a "text"  year.  That works fine.  Not the best answer but it will do.  I do not know why the numeric year was so glitchy.

Kurt_Bremser
Super User

The prompt has to pop up every time the code is run, and the resulting macro variable can only be expected to be valid for the particular code that the prompt is assigned to. If you want to use the same prompt value in several codes, you must assign the prompt to all those codes.

cbrotz
Pyrite | Level 9

Yes it is added to all code.

Kurt_Bremser
Super User

The message is clear: the macro variable does not exist when the code runs. And the WHERE condition you post here is not the one in the log you posted in your OP, where you only test for &YEAR_19_21.

Are you sure this happens in the code you assigned the prompt to?

Sajid01
Meteorite | Level 14

Hello @cbrotz 
Did you try to debug for errors?

At the minimum please have the following statement before running proc sql. It shows if the values is available or not before execution of the proc sql;

 %put &YEAR._19_21

  

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 1904 views
  • 0 likes
  • 5 in conversation