BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8

Need help if there is away to apply date format conditionally based on the values:

 

Var1

13886

13353

      .

     0

     1

 

For example, var1  how would like to apply date9. format to first two obeseravtions and leave the remaining records as is. So var2 looks like below:

 

Var1                                                 var2

13886                                       07JAN1998

13353                                     23JUL1996

      .                                                   .

     0                                                   0

     1                                                   1

 

 

3 REPLIES 3
Tom
Super User Tom
Super User

Make your own custom format.

proc format;
value mydate ;
  0,1 = [1.]
  other=[date9.]
;
run;

proc print data=have;
   format var1 mydate9.;
run;

Hopefully your real dates don't include the first two days of 1960.

SASPhile
Quartz | Level 8
mydate is not resolving to date9. format.But it gives a numeric value
Tom
Super User Tom
Super User

Works fine for me.

741   proc format;
742   value mydate 0,1=[1.] other=[date9.];
NOTE: Format MYDATE is already on the library WORK.FORMATS.
NOTE: Format MYDATE has been output.
743   run;

NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


744   data _null_;
745     do x=-1 to 2,today();
746       put x= comma7. +1 x=mydate9.;
747     end;
748   run;

x=-1  x=31DEC1959
x=0  x=0
x=1  x=1
x=2  x=03JAN1960
x=21,746  x=16JUL2019

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 3 replies
  • 431 views
  • 1 like
  • 2 in conversation