DATA Step, Macro, Functions and more

replacing missing date values in a column with new date

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

replacing missing date values in a column with new date

Hello Folks

 

I am a long time reader first time Poster.

I'm a beginner in SAS with no programming/coding background. Currently stuck with a school assignment wherein i have to replace a missing date values in a Column (with existing mmddyy10. format)_with a given date 01/20/2001(mmddyy10.).

i used the following code 


proc format;
value ndate
. = 01/20/2001;
RUN;

proc print data=pipe_2 (obs=20);
FORMAT deactdt ndate.;
RUN;

 

It replaces the missing date values with 01/20/2001, but some how the existing date values in the column converted to actual sas date values.

 

how do i retain those existing date values in their initial assigned format which is MMDDYY10 AND ALSO KEEP THE NEWW REPLACED VALUES TO MMDDYY10.

 

YOUR response will be appreciated.

 

thanks

Have a wonderful day.

 

 

 

 

 


Accepted Solutions
Solution
‎11-05-2017 01:15 AM
Super User
Posts: 6,908

Re: replacing missing date values in a column with new date

It's not clear whether you are pursuing the proper path or not.  A format changes what prints, but doesn't change the data values themselves.  If changing the data values is the goal, you could try:

 

data pipe_3;

set pipe_2;

if deactdt = . then deactdt = '20jan2001'd;

run;

 

You could print that data set as is, since any format applied to DEACTDT would remain unchanged.

 

To get your original format attempt to work, you could try:

 

proc format;

value ndate

. = '01/20/2001'

other = [mmddyyS10.];

run;

 

I can't test this until Monday, but that should work.  Note that the S in the format name indicates that the separator between parts of the date should be a slash.  (There are alternatives.)

View solution in original post


All Replies
Valued Guide
Posts: 626

Re: replacing missing date values in a column with new date

Can you post the log?
Solution
‎11-05-2017 01:15 AM
Super User
Posts: 6,908

Re: replacing missing date values in a column with new date

It's not clear whether you are pursuing the proper path or not.  A format changes what prints, but doesn't change the data values themselves.  If changing the data values is the goal, you could try:

 

data pipe_3;

set pipe_2;

if deactdt = . then deactdt = '20jan2001'd;

run;

 

You could print that data set as is, since any format applied to DEACTDT would remain unchanged.

 

To get your original format attempt to work, you could try:

 

proc format;

value ndate

. = '01/20/2001'

other = [mmddyyS10.];

run;

 

I can't test this until Monday, but that should work.  Note that the S in the format name indicates that the separator between parts of the date should be a slash.  (There are alternatives.)

Occasional Contributor
Posts: 9

Re: replacing missing date values in a column with new date

Posted in reply to Astounding
astounding data step fixed my problem.

thanks a lot.
Have A Wonderful Day.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 369 views
  • 0 likes
  • 3 in conversation