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

...

...

ELSE IF '26JUN2016'd < todaydate <= '03JUL2016'd THEN DO;

begin_date = '26JUN2016'd;
end_date='03JUL2016'd;
END;%

/*format begin_date end_date date9.;*/

%LET start = %sysevalf(begin_date);

%LET end = %sysevalf(end_date);

I actually want to pass the date from above, 26JUN2016 to the %start variable and 03JUL2016 to the %end variable and have been trying different %EVALs to get it to evaluate what is begin_date and what is end_date

The issue is that if I just plainly put in

     %LET start = begin_date;

it only passes along the text "begin_date" and does not solve for the what begin_date is assigned to.

and if I use %EVAL, then the macro looks for a numeric whereas I actually want the date (or text) of "26JUN2016" is equal to &start

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Is that in a data step?

If so to create a macro variable in a data step you need to use call symputx to create the macro variable not a %let statement.

View solution in original post

5 REPLIES 5
Reeza
Super User

Is that in a data step?

If so to create a macro variable in a data step you need to use call symputx to create the macro variable not a %let statement.

WendyCzika
SAS Employee

Yes as Reeza says, you would need to do something like the following inside the DATA step:

...
begin_date = '26JUN2016'd;

end_date='03JUL2016'd;

call symput("start",begin_date);

call symput("end", end_date);

...

run;

Then after the DATA step, the macro variables start and end are available to use with the actual dates in them.

zhou_larry
Calcite | Level 5

Indeed it is. So I changed it to:

call symputx("start", begin_date);

call symputx("end", end_date);

format begin_date end_date start end date9.;

%put &start;

%put &end;

and now it's passing through!!

but now the date is a SAS date, so '12APR2015' = 20190 which isn't ideal. and formatting it isn't exactly working

So the next data step is something like:

data work.xx;

keep x, y, z;

  WHERE (&start) < datepart(order_date) <= (&end);

but now because it's a SAS date, it looks at 20190 < datepart(order_date) which comes up blank when it runs. How do I made the order_date into a SAS format or how do I make the 20190 pass as a date9. instead of a SAS date?

Reeza
Super User

Actually your WHERE condition should still resolve properly.

Your data step is incorrect the keep statement has comma's and there is no SET dataset.

Tom
Super User Tom
Super User

If you want the macro variables to contain values that would be valid to use in generating the logical expression

(&start <  XX < &end)

where XX is a date expression then you have two choices.

1) Store the actual integer values that represent the start and end dates.

CALL SYMPUTX('START',put(begin_date,10.))

2) Store the value as a date literal.

CALL SYMPUTX('START',cats("'",put(begin_date,date9.)."'d"))

You could also create the macro variable with DATE9 formatted date strings and then add the ""d in the where clause.

CALL SYMPUTX('START',put(begin_date,date9.));

...

("&start"d < XX < "&end"d)



sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1290 views
  • 8 likes
  • 4 in conversation