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

Hi

 

I hope some one can help me.

 

There is a wrong date in the original database.  I don't want to go back to the original database. 

 

I have searched on it in google and at this website and found NO ANSWER.

      

https://communities.sas.com/t5/Base-SAS-Programming/how-to-convert-char-var-to-sas-date/td-p/45067

 

Now, here is what the contents of the dataset say for that variable.

 

woundvstdateNum8MMDDYY8

 

My code is:

 

data initial;

set aung.initialdat_mg2;

if id=55 then woundvstdate=04/20/10;

 

proc print;

run;

 

 

My outpout is:

 

 

Obs id woundvstdate1
5501/01/60

Obviously, that is wrong.

I know there more wrong dates and don't want to keep going back to the original dataset.

I know this will happen in future endeavors.

 

Is there a way to do this in a datastep? 

 

thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@mgrzyb wrote:

 

There is a wrong date in the original database.  I don't want to go back to the original database. 

 

...

My code is:

 

data initial;

set aung.initialdat_mg2;

if id=55 then woundvstdate=04/20/10;



When you type 04/20/10, it is division. You are dividing 04 by 20 and then dividing by 10.

 

To indicate that 04/20/10 is a date value, use

 

if id=55 then woundvstdate='20APR10'D;
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

@mgrzyb wrote:

 

There is a wrong date in the original database.  I don't want to go back to the original database. 

 

...

My code is:

 

data initial;

set aung.initialdat_mg2;

if id=55 then woundvstdate=04/20/10;



When you type 04/20/10, it is division. You are dividing 04 by 20 and then dividing by 10.

 

To indicate that 04/20/10 is a date value, use

 

if id=55 then woundvstdate='20APR10'D;
--
Paige Miller
mgrzyb
Quartz | Level 8

Thankyou!

 

That worked.  I also  tried this, and it seemed to work after  I checked out proc contents again. 

 

If there is a difference between the 2, please let know. 

 

               if id=55 then put=(woundvstdate=04/20/10);

 

 

Thank you again!!!!

PaigeMiller
Diamond | Level 26

PROC CONTENTS would not contain information about whether or not  changing the value of a variable was successful or not.

 

if id=55 then put=(woundvstdate=04/20/10);

 

I don't see how this code would successfully change the value of a variable either.

 

The bottom line is you have to LOOK at the data set with your own eyes, and see if the value is correct in the data set or not. PROC CONTENTS, and PUT statements don't suffice.

--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 741 views
  • 0 likes
  • 2 in conversation