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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

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

View solution in original post

3 REPLIES 3
TarunKumar
Pyrite | Level 9

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;

Jagadishkatam
Amethyst | Level 16

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
overmar
Obsidian | Level 7

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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 935 views
  • 3 likes
  • 4 in conversation