BookmarkSubscribeRSS Feed
Aashi07
Calcite | Level 5

For task: If in the date columns there is 01/01/1900, replace with 01/01/0001,

I tried the following code:

 

data work.CGDM_IMP_PPLC;
              infile "&chemin_CGDM./W6_Extraction_CGDM_PPLC.csv" 
              delimiter='|' firstobs=2 lrecl=32767 missover dsd termstr=lf encoding='utf-8';
  
          format 
        DATE_DONNEES DDMMYY10. 
        DATE_ENTREE_ENTREPRISE DDMMYY10.
        DATE_SORTIE_ENTREPRISE DDMMYY10.
        DATE_ENTREE_ETABL DDMMYY10.
        DATE_SORTIE_ETABL DDMMYY10.
        IND_VIP 1.
        IND_SALARIE_DCD 1.
              ;
              input
       SOURCE
        DATE_DONNEES :YYMMDD10.
       DATE_ENTREE_ENTREPRISE :YYMMDD10.
        DATE_SORTIE_ENTREPRISE :YYMMDD10.
        DATE_ENTREE_ETABL :YYMMDD10.
        DATE_SORTIE_ETABL :YYMMDD10.
        IND_VIP
        IND_SALARIE_DCD

              ;
     if DATE_SORTIE_ENTREPRISE = '01/01/1900'd
           then DATE_SORTIE_ENTREPRISE = '01/01/0001'd;

run;

 

But I am obtaining this error:

Aashi07_1-1721814376188.png

 

 

3 REPLIES 3
PaigeMiller
Diamond | Level 26

In an IF statement, you MUST use the date literal

 

if DATE_SORTIE_ENTREPRISE = '01JAN1900'd ...

 

to search for 01/01/1900.

 

However, I do not believe it is possible to assign a date of 01/01/0001, and so I think your task is impossible. Why do you want 01/01/0001 anyway? Why not just assign a missing value?

--
Paige Miller
ballardw
Super User

Currently the earliest date that SAS will use is 1 Jan 1582 and relates to when certain countries adopted the Gregorian calendar.

 

Custom informat and formats can approximate the behavior requested: (Note to @Aashi07 if your other dates are in Day Month Year order use DDMMYY10. below)

proc format library=work;
  invalue  mydates
  '01/01/1900'=.M
  other = [mmddyy10.]
  ;
  value mydates
  .M = '01/01/0001'
  other=[mmddyy10.]
  ;
run;

data example;
   input date mydates.;
   format date mydates.;
datalines;
01/01/1900
12/31/2021
02/01/2023
;

Assign a special missing, like the .M and use a custom format to display the special missing with desired appearance when needed. The missing values will not be included in any calculations unless using an option that specifies missing values will be used.

Tom
Super User Tom
Super User

Date literals require a string that the DATE informat can convert to a date.

But you cannot have a date before 1582.  So if the CSV file use strings like 0001/01/01 they will be read by the YYMMDD informat as missing.

 

So it sounds like you just need to change the IF statement to assign a missing value instead.  

if DATE_SORTIE_ENTREPRISE = '01JAN1900'd
  then DATE_SORTIE_ENTREPRISE = .
;

 Or you could assign one of the 27 other special missing values instead.

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!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 132 views
  • 2 likes
  • 4 in conversation