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

Hello Everyone

 

I am trying to assign a date to a macro variable and using that macro variable to subset a data from a dataset. It's throwing me an error. Here is the code:

 

/*Assigning the macro variable the 27th Jan 2018 date*/
%let date_comp= %SYSFUNC(INTNX(DAY,%SYSFUNC(TODAY()),-3),date9.);
%put &date_comp.;
27JAN2018

DATA want(where=( Ship_Date >=&date_comp.));
set have;
run;



The want data is throwing me an error. This is the error.

 

data want (where=(ship_date >=&date_comp.));
NOTE: Line generated by the macro variable "DATE_COMP".
1 27JAN2018
-------
22
76
ERROR: Syntax error while parsing WHERE clause.
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>,
=, >, >=, AND, EQ, GE, GT, LE, LT, NE, OR, ^=, |, ||, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

3721 set have;
3722 run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

ERROR: Syntax error while parsing WHERE clause.

Please help me with this. 

 

Thanks

Chandan Mishra

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
DATA want(where=( Ship_Date >="&date_comp"d));
set have;
run;

Formatted SAS dates which are text must be enclosed in single or double quotes, followed by the letter D (and since you are using a macro variable, it must be double quotes).

 

You can save yourself a bunch of coding by not formatting the macro variable as date9., just leave it as an integer.

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26
DATA want(where=( Ship_Date >="&date_comp"d));
set have;
run;

Formatted SAS dates which are text must be enclosed in single or double quotes, followed by the letter D (and since you are using a macro variable, it must be double quotes).

 

You can save yourself a bunch of coding by not formatting the macro variable as date9., just leave it as an integer.

--
Paige Miller
RW9
Diamond | Level 26 RW9
Diamond | Level 26
DATA want(where=( Ship_Date >= "&date_comp."d));

Is the update you need, however why bother at all, it does nothing more than:

data want;
  set have;
  where ship_date > today()-3;
runl

Except making the code far harder to read, maintain and debug.  KISS - Keep It Simple Smart - is a mantra you should as programmer live by!

chandan_mishra
Obsidian | Level 7

Hello 

 

Thanks for your amazing reply. I am using a master file to run all the separate codes and want data is in the separate code. It's only because I don't have to change the code every time in the separate code, I used a macro variable in the master file and using it in the separate code. But I understood what you want to say. Thank you.

 

Thanks

Chandan Mishra

art297
Opal | Level 21

Try:

DATA want(where=( Ship_Date >="&date_comp."d));

The macro variable, itself, only contains text.

 

Art, CEO, AnalystFinder.com

 

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 27265 views
  • 6 likes
  • 4 in conversation