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
SAS Super FREQ
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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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