BookmarkSubscribeRSS Feed
rohitkrishna
Calcite | Level 5

Hi team,

I had one regarding the date format checkpoint

the question is  

if the hdrdate is 20200120

it updated fine in the table but I was given instead of 20 I have given 40 in the dd I mean to date it accepted that one how come it happens I don't know bez a month date has ending with the 31 only right 

so i requesting you give some solution above problem how to put a checkpoint on the issue.

 

Thanks & Regards 

Rohitkrishna

14 REPLIES 14
Kurt_Bremser
Super User

@rohitkrishna wrote:

Hi team,

I had one regarding the date format checkpoint

the question is  

if the hdrdate is 20200120

it updated fine in the table but I was given instead of 20 I have given 40 in the dd I mean to date it accepted that one how come it happens I don't know bez a month date has ending with the 31 only right 

so i requesting you give some solution above problem how to put a checkpoint on the issue.

 

Thanks & Regards 

Rohitkrishna


Sorry, I can't make sense of this.

Please supply example data, code and logs that illustrate your issue.

rohitkrishna
Calcite | Level 5
Hi KurtBremser
Thanks for the quick response
ys sure i will give the example plz find below
{
first the hdrdate = 20200120 it's in ccyymmdd format
and it updated fine in table
then i have given hdrdate = 20200140 for testing
above date also updated
my question is how come it updated a month have only 31 days it went beyond 31 days right
how to put a checkpoint on the above issue

Thanks & Regards
Rohitkrishna
rohitkrishna
Calcite | Level 5
Hi KurtBremser
thanks for the response
ya sure
{
DATA DT_FT;
INFILE DATALINES;
INPUT @1 DATE $CHAR8.;
DATALINES;
20200120
20200140
;
RUN;
PROC PRINT DATA = DT_FT;
RUN;
output:
Obs DATE

1 20200120
2 20200140
my ask is how the second date has been updated
it is greater than 31 right
so my expected output is
{
20200120 it printing fine
but second, has to print error
bez it is greater than 31
}
plz kindly give some solution for the above issue
Thanks & Regards
Rohit

ed_sas_member
Meteorite | Level 14

Hi @rohitkrishna 

 

what if you read the data directly as a SAS date using the YYMMDD10. informat?

DATA DT_FT;
INFILE DATALINES;
INPUT @1 DATE:YYMMDD10.;
FORMAT DATE:YYMMDD10.;
DATALINES;
20200120
20200140
;
RUN;

PROC PRINT DATA = DT_FT;
RUN;

 

rohitkrishna
Calcite | Level 5
Hi ed_sas_member,
Thanks for the response it's working fine but my requirement is how to put a check point to stop the displaying the 20200140
and moreover, my expected output is
20200120
not 2020-01-20
i tried to give yymmdd8. but it shows
Obs DATE

1 20-01-20
2 .
above one i got
so plz kindly respond on the above issue
Thanks & Regards
Rohit
ed_sas_member
Meteorite | Level 14

Hi @rohitkrishna 

 

Please try this:

DATA DT_FT;
INFILE DATALINES;
INPUT @1 DATE $CHAR8.;
length check $ 20;
IF input(DATE,YYMMDD10.) ne . then check=Date;
else check = "not valid: "||date;
DATALINES;
20200120
20200140
;
RUN;

PROC PRINT DATA = DT_FT;
RUN;
rohitkrishna
Calcite | Level 5
Hi ed_sas_member
Thanks for the quick response
ya it's superb it's working fine
But my small request is
if the date is less then that it displays not valid
like
date < 31 display not valid
above condition possible kindly gives some suggestions
Thanks & Regards
Rohit
ed_sas_member
Meteorite | Level 14

Hi @rohitkrishna 

 

Here is a slight change:

DATA DT_FT;
INFILE DATALINES;
INPUT @1 DATE $CHAR8.;
length check $ 20;
IF 0 < day(input(DATE,YYMMDD10.)) <= 31 then check=Date;
else check = "not valid: "||date;
DATALINES;
20200120
20200140
;
RUN;

PROC PRINT DATA = DT_FT;
RUN;
rohitkrishna
Calcite | Level 5
Hi ed_sas_member
Thank you very much it's working
Thanks & Regards
Rohit
ed_sas_member
Meteorite | Level 14
Thank you @rohitkhrishna!
Could you please accept the solution to mark the topic as answered?
Reeza
Super User

Because your field is CHAR8 it accepts anything that fits that structure. 

If you'd like to have a date and verify it's a valid date, make the column a numeric type with a date format applied. Then if you try to insert an invalid date it will throw an error.

 

DATA DT_FT;
INFILE DATALINES;
informat date yymmdd8.;
format date date9.;
INPUT @1 DATE ;
DATALINES;
20200120
20200140
;
RUN;

@rohitkrishna wrote:
Hi KurtBremser
thanks for the response
ya sure
{
DATA DT_FT;
INFILE DATALINES;
INPUT @1 DATE $CHAR8.;
DATALINES;
20200120
20200140
;
RUN;
PROC PRINT DATA = DT_FT;
RUN;
output:
Obs DATE

1 20200120
2 20200140
my ask is how the second date has been updated
it is greater than 31 right
so my expected output is
{
20200120 it printing fine
but second, has to print error
bez it is greater than 31
}
plz kindly give some solution for the above issue
Thanks & Regards
Rohit


 

Tom
Super User Tom
Super User

It is very difficult to understand what you are actually asking for.

It sounds like you have string of 8 digits and you want to use it to create a date. So use the INPUT() function with an appropriate INFORMAT will do that.

But it also sounds like you want to add a business rule that if the number represented by the last two digits is invalid as a date then to use the last day of the month implied by the first 6 digits.

Something like this:

data want;
   set have;
   datevar=input(hdrdate,??yymmdd8.);
   if missing(datevar) and not missing(hdrdate) then do;
     datevar=input(hdrdate,??yymmn6.);
     if not missing(datevar) then datevar=intnx('month',datevar,0,'end');
  end;
  format datevar date9.;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 14 replies
  • 1410 views
  • 0 likes
  • 5 in conversation