BookmarkSubscribeRSS Feed
greelights01
Calcite | Level 5

Hi everyone,

I am trying to work with a dataset and have been struggling with creating a new variable involving date.

In my dataset (.sas7bdat), I have a variable with a date informat (mm/dd/yy10.).

What I am trying to do is to create a variable called 'index' that codes 0 if date before 5/1/2010 and 1 if date is after 5/1/2010.

I tried to code in a data step:

data one; set new;

if date>=05/01/2010 then index=1;

else index=0;

run;

When I proc print, the index=1 for all of my observations.

What is wrong with my code? I have been struggling for hours.. Please help!!

Thank you!

4 REPLIES 4
Haikuo
Onyx | Level 15

"if date>=05/01/2010 then index=1;"

date here is numeric, while   05/01/2010 is not. When comparing,  05/01/2010 is taken as missing value which is the smallest. That is why you always get index=1.

Switch it to :

"if date>='01MAY2010'D then index=1;" 

greelights01
Calcite | Level 5

Thank you so much Hai.kuo!

Worked really well. You're awesome:)

Howles
Quartz | Level 8

05/01/2010 is not a valid date literal, but it is a valid numeric expression.

( (5/1)/2010 ) evaluates to 0.0024875, which interprets as 1 January 1960.

Haikuo
Onyx | Level 15

Aha, miss that part, should have run the test. Thanks, @Howles!

OP, please weight in this correct information.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 968 views
  • 2 likes
  • 3 in conversation