BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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;
set IFM.market;
where datepart(Market_Start_Time) >= &StartTime.d
and datepart(Market_End_Time) <= &EndTime.d;
run;

Thanks!

Message was edited by: BS_CISO Message was edited by: BS_CISO
4 REPLIES 4
deleted_user
Not applicable
For some reason the code won't post completely. There is a "Endtime.d" and a "run;" following the above code.
Cynthia_sas
Diamond | Level 26
Hi:
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:

[pre]
where birthday = "15Nov1950"d;

%let bday = 15Nov1950;
where birthday = "&bday"d;
[/pre]

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.

cynthia
RichardH_sas
SAS Employee
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:

'01Jan1952'd

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.
deleted_user
Not applicable
Thanks for the responses.

Richard, perfect, exactly what I was trying to do, thank you.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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