BookmarkSubscribeRSS Feed
wottma
Calcite | Level 5

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 🙂

 

 

 

3 REPLIES 3
PaigeMiller
Diamond | Level 26

@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?

--
Paige Miller
Reeza
Super User

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 🙂

 

 

 


 

Tom
Super User Tom
Super User

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