Building models with SAS Enterprise Miner, SAS Factory Miner, SAS Visual Data Mining and Machine Learning or just with programming

Want a character operand, not a numeric, but is not evaluating

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Want a character operand, not a numeric, but is not evaluating

...

...

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


Accepted Solutions
Solution
‎04-16-2015 03:45 PM
Super User
Posts: 17,774

Re: Want a character operand, not a numeric, but is not evaluating

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


All Replies
Solution
‎04-16-2015 03:45 PM
Super User
Posts: 17,774

Re: Want a character operand, not a numeric, but is not evaluating

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.

SAS Super FREQ
Posts: 270

Re: Want a character operand, not a numeric, but is not evaluating

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.

New Contributor
Posts: 4

Re: Want a character operand, not a numeric, but is not evaluating

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?

Super User
Posts: 17,774

Re: Want a character operand, not a numeric, but is not evaluating

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.

Super User
Super User
Posts: 6,498

Re: Want a character operand, not a numeric, but is not evaluating

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)



☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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