Hi SAS-Community,
I have a date variable (informat ddmmyy10.) called hctzdate. I am trying to replace one specific date with a missing value (a '.'). In my example I would like to replace the date 03/01/2007.
How can I do that?
I tried:
data work.test1_hctz; set work.test_hctz;
if hctzdate ='03jan2007'd then hctzdate=.;
informat hctzdate ddmmyy10.;
run;
There wasn't an error in the log file, however nothing happened when I looked at the data in the viewtable. I am using SAS 9.4. Can anyone help me?
Thanks a lot in advance 🙂
@wottma wrote:
Hi SAS-Community,
I have a date variable (informat ddmmyy10.) called hctzdate. I am trying to replace one specific date with a missing value (a '.'). In my example I would like to replace the date 03/01/2007.
How can I do that?
I tried:
data work.test1_hctz; set work.test_hctz;
if hctzdate ='03jan2007'd then hctzdate=.;
informat hctzdate ddmmyy10.;
run;
There wasn't an error in the log file, however nothing happened when I looked at the data in the viewtable. I am using SAS 9.4. Can anyone help me?
Thanks a lot in advance 🙂
Since we don't have your data, I'm going to guess that hctzdate is really a date/time value and not a date value. Can you show us a few UNformatted values of this variable?
In general your code looks correct so are you sure it didn't work?
You need to look at the type and format, the informat of a variable isn't particularly useful unless you're reading in the data. You should remove your INFORMAT statement or change it to a FORMAT statement. If you do have a datetime as suggested by @PaigeMiller you can use the DATEPART() function to get just the date for the comparison.
data work.test1_hctz;
set work.test_hctz;
if hctzdate ='03JAN2007'd then hctzdate=.;
format hctzdate ddmmyy10.;
run;
@wottma wrote:
Hi SAS-Community,
I have a date variable (informat ddmmyy10.) called hctzdate. I am trying to replace one specific date with a missing value (a '.'). In my example I would like to replace the date 03/01/2007.
How can I do that?
I tried:
data work.test1_hctz; set work.test_hctz;
if hctzdate ='03jan2007'd then hctzdate=.;
informat hctzdate ddmmyy10.;
run;
There wasn't an error in the log file, however nothing happened when I looked at the data in the viewtable. I am using SAS 9.4. Can anyone help me?
Thanks a lot in advance 🙂
SAS stores dates as the number of days. Perhaps your values are non-integers? The date formats will ignore the fractional part of the value.
221 data test; 222 do x=.1,.5,.6; 223 date=today()+x; 224 put x= date=comma10.1 +1 date yymmdd10. ; 225 end; 226 run; x=0.1 date=21,955.1 2020-02-10 x=0.5 date=21,955.5 2020-02-10 x=0.6 date=21,955.6 2020-02-10
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.