BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
GN0001
Barite | Level 11

Hello team,

I have code below. I added tday to datasetp. It keeps saying that tday doesn't exist.

data combo2;
tday = date();
format tday MMDDYY10.;
set combine;
where tday - someonedob <= 2;
run;

Log:
ERROR: Variable tday is not on file WORK.COMB02.

Any tip is greatly appreciated?

Thanks,

Blue blue

Blue Blue
1 ACCEPTED SOLUTION

Accepted Solutions
GN0001
Barite | Level 11

Hello Paige,

It is acknowledged. I won't.

I understand that we can't create a variable in a data step and then put where clause on that variable on the same data step. Is this what meant by this?

"The WHERE statement applies to all data sets in the preceding SET, MERGE, MODIFY, or UPDATE statement, and variables that are used in the WHERE statement must appear in all of those data sets. You cannot use the WHERE statement with the POINT= option in the SET and MODIFY statements."

Regards,

Blue

Blue Blue

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

When there is an error in the log, show us the ENTIRE log for this data step. Do not show us part of the log. Do not show us only the errors. (And please don't make us ask for this repeatedly).

 

The WHERE statement cannot be used like that. According to the documentation:

 

The WHERE statement applies to all data sets in the preceding SET, MERGE, MODIFY, or UPDATE statement, and variables that are used in the WHERE statement must appear in all of those data sets. You cannot use the WHERE statement with the POINT= option in the SET and MODIFY statements.

 

Your usage of WHERE does not meet the requirements stated. The variable TDAY is not a part of the variables in the preceding SET statement. So it can't be used like that.

 

However, if you replace WHERE with IF, then the code works.

--
Paige Miller
GN0001
Barite | Level 11

Hello Paige,

It is acknowledged. I won't.

I understand that we can't create a variable in a data step and then put where clause on that variable on the same data step. Is this what meant by this?

"The WHERE statement applies to all data sets in the preceding SET, MERGE, MODIFY, or UPDATE statement, and variables that are used in the WHERE statement must appear in all of those data sets. You cannot use the WHERE statement with the POINT= option in the SET and MODIFY statements."

Regards,

Blue

Blue Blue
Tom
Super User Tom
Super User

The WHERE clause is applied as the data is read from the source dataset(s).  So you cannot reference variables in the WHERE statement that do not exist in the source dataset(s) because they don't exist!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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