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
@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.
DATASET
CODE
LOG
EXPECTED OUTPUT
Please.
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;
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;
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 wrote:
date < 31 display not valid
And what about February, April, June??? Those months do not have a 31st at all.
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
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.