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
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
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;
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
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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.