turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- How to change the number to date?

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-13-2014 11:49 PM

Hello every SAS users, here is a very simple question and i need your help!!

I want to let the records with T2DM=0 change its Diag_day to 01/01/1998.

But I meet some problem while programming it.

Can anyone help me solve the problem?

Thanks!!!!!!

data test4;

set test3;

if T2DM=0 then Diag_day_Q=19980101;

if T2DM=0 then Diag_day=mdy(substr(Diag_day_Q,5,2), substr(Diag_day_Q,7,2),substr(Diag_day_Q,1,4));

format Diag_day mmddyy10.;

run;

NOTE: Numeric values have been converted to character values at the places given by: (Line)Column).

16841:36 16841:60 16841:83

NOTE: Character values have been converted to numeric values at the places given by: (Line)Column).

16841:29 16841:53 16841:76

NOTE: Missing values were generated as a result of performing an operation on missing values.

Each place is given by: (Number of times) at (Line)Column).

183960 at 16841:25

NOTE: There were 386182 observations read from the data set WORK.TEST3.

NOTE: The data set WORK.TEST4 has 386182 observations and 52 variables.

NOTE: DATA statement used (Total process time):

real time 0.45 seconds

cpu time 0.39 second

Accepted Solutions

Solution

02-14-2014
01:56 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Willy

02-14-2014 01:56 AM

Please try the below code

data test4;

set test3;

if T2DM=0 then Diag_day_Q=**"19980101"**;

if T2DM=0 then Diag_day=mdy(input(substr(Diag_day_Q,5,2),8.), input(substr(Diag_day_Q,7,2),8.), input(substr(Diag_day_Q,1,4),8.));

format Diag_day mmddyy10.;

run;

From the above, no notes in the log will be generated. Used character data in substr functions. Please check the **Bold** letters.

Tried your code, we will get the output but with notes.

To avoid it, use the character data in substr and compress function, instead of the numeric data.

Thanks,

Jag

Thanks,

Jag

Jag

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Willy

02-14-2014 01:04 AM

i think this will work

data test4;

format Diag_day date10.;

Diag_day_Q = 19980101;

Diag_day = mdy(substr(compress(Diag_day_Q),5,2), substr(compress(Diag_day_Q),7,2),substr(compress(Diag_day_Q),1,4));

run;

Solution

02-14-2014
01:56 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Willy

02-14-2014 01:56 AM

Please try the below code

data test4;

set test3;

if T2DM=0 then Diag_day_Q=**"19980101"**;

if T2DM=0 then Diag_day=mdy(input(substr(Diag_day_Q,5,2),8.), input(substr(Diag_day_Q,7,2),8.), input(substr(Diag_day_Q,1,4),8.));

format Diag_day mmddyy10.;

run;

From the above, no notes in the log will be generated. Used character data in substr functions. Please check the **Bold** letters.

Tried your code, we will get the output but with notes.

To avoid it, use the character data in substr and compress function, instead of the numeric data.

Thanks,

Jag

Thanks,

Jag

Jag

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Willy

02-15-2014 03:08 PM

This seems like a rather roundabout way to define a date, why not just write

data test4;

set test3;

if T2DM=0 then Diag_day='01JAN1998'd;

format Diag_day mmddyy10.;

run;

Essentially if T2DM is equal to 0 then diag_day is converted to the SAS date for 01/01/1998

Also this way you don't have to create an extra variable in Diag_day_Q which you likely will have to delete in the future, or have to make sure that your substr commands are all in the right places.

For reference you can always directly specify a date by putting it into the DDMMMYYYY format wrapping it in ' and putting a d after it.