Desktop productivity for business analysts and programmers

Assign a Macro to an EG Parameter

Not applicable
Posts: 0

Assign a Macro to an EG Parameter

Is there a way to assign a macro to an existing Parameter in EG so that it prompts the user for a date range? I have the parameter set in EG but not sure how to go about this or if it is even possible. I need to be able to edit the following code for a prompt screen.

I have the following code:

%let DayLightSaveTime_Hours = 7;

%let StartTime = %str('20DEC2008');
%let EndTime = %str('21DEC2008');

data WORK.input_market;
where datepart(Market_Start_Time) >= &StartTime.d
and datepart(Market_End_Time) <= &EndTime.d;


Message was edited by: BS_CISO Message was edited by: BS_CISO
Not applicable
Posts: 0

Re: Assign a Macro to an EG Parameter

Posted in reply to deleted_user
For some reason the code won't post completely. There is a "Endtime.d" and a "run;" following the above code.
Posts: 9,426

Re: Assign a Macro to an EG Parameter

Posted in reply to deleted_user
It is generally a bad idea to "prequote" your macro variable values in the %LET statement. The quotes belong to the WHERE clause...
this is perfectly valid SAS code:

where birthday = "15Nov1950"d;

%let bday = 15Nov1950;
where birthday = "&bday"d;

the quotes around your date constant can be either single or double quotes. Putting the quotes, where they belong, in the WHERE statement or
clause, allows you to avoid "pre-quoting", using %str and possibly needing %unquote to undo the effects of %str.

I don't work with EG that much, so will defer to EG users on how to assign a macro variable a value with a parameter. But I believe that these
general rules for macro processing still hold:
1) have working code and put quotes in the working code where needed
2) DO NOT put quotes in your %LET statement
3) Once you have working code, replace the hardcoded values with macro variable references and test the code again
4) If you need macro conditional logic, take your macro-ized code and put it into a macro program for invocation.
5) Use only the "strength" of macro quoting function that you need. For example, if you need to prevent resolution of a macro variable at compile time,
don't use an execution time quoting function and vice versa. Do not use macro quoting functions unless you REALLY need them.

SAS Employee
Posts: 149

Re: Assign a Macro to an EG Parameter

Posted in reply to deleted_user
Sure, I've created Date parameters from EG many times. The value you choose from the prompt will be returned to code as if you typed:


for example. So, quotes and the "d" built in, for better or worse.

1. In the Parameters Manager, create your parameter StartTime with a data type of Date. Always best to set a default date, check Prompt for Value and check A Value is Required at Runtime.

2. Right click on the Code Node or Task with the parameter reference and choose Properties. From the Parameters tab, add the parameter(s) in question so they're associated with the code or task.

3. In the code itself, make sure you write it like

where datepart(Market_Start_Time) >= &StartTime

keeping in mind how EG returns that parameter value as above.
Not applicable
Posts: 0

Re: Assign a Macro to an EG Parameter

Posted in reply to RichardH_sas
Thanks for the responses.

Richard, perfect, exactly what I was trying to do, thank you.
Ask a Question
Discussion stats
  • 4 replies
  • 3 in conversation