BookmarkSubscribeRSS Feed
GN0001
Barite | Level 11

Hello team,

data mydata (keep = plan id  orderenddate year month);
set mydata1;
year = year(orderenddate);
month = month(oorderenddate);
run;

/*Year and months are not in dataset, I added them for the functions that I have use*/

data mydata2;
set mydata1;
where year =2022;
run;

where year = 2022 give errors. orderenddate is numeric data type which is formatted as a date in dataset: 2022-03-13.

How can I overcome this error?

Regards,

b&b

Blue Blue
4 REPLIES 4
SASKiwi
PROC Star

Read the dataset you added them to:

data mydata2;
set mydata; * You created them in mydata not mydata1;
where year =2022;
run;
ballardw
Super User

I believe we have asked that when there are errors to copy the log with procedure or data step code and all of the note, warnings and errors; open a text box on the forum using the </> icon and paste the text with all of that.

 

Don't make us guess what the error is or where it occurs.

 

You may also want to run proc contents on your data set and show us the results.

BrahmanandaRao
Lapis Lazuli | Level 10

Use IF statement it converts any data type num to char and char to num this is the one  difference between 

IF & Where 

where can not convert char to numeric

ballardw
Super User

@BrahmanandaRao wrote:

Use IF statement it converts any data type num to char and char to num this is the one  difference between 

IF & Where 

where can not convert char to numeric


But you can put functions in Where statements such as

where year(somedatevariable)= 2022;

Unless that "year" variable is to be used for something else it is not even needed.

Many times when you need a "year" variable it may be quite possible that applying the YEAR format to a date variable will suffice.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 660 views
  • 2 likes
  • 4 in conversation