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.

Anandkvn
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

@Anandkvn 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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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