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