SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Rixile106
Fluorite | Level 6

Good day expect.

 

am running the below script and and am getting the this error message

Spoiler
ERROR: INPUT function reported 'ERROR: Invalid date value' while processing WHERE clause.



PROC SQL;
	CREATE TABLE INSTA_A AS
		SELECT INPUT(PUT(COMPRESS(INPUT(PUT(ACC_NO,13.),$13.)||PUT(SERIAL_NO,Z3.)),$16.),16.) AS ACCOUNT
			,A_COMM_DT AS COMM_DT
			,A_EXP_DT AS EXP_DT
			,'A' AS INSTRUCTION
		FROM VBM.INST_A
		WHERE INPUT(PUT(A_COMM_DT,Z8.),YYMMDD8.) > TODAY() + 365
		;
QUIT;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You can make the error MESSAGE go away by adding the ? modifier before the informat.

input(put(a_comm_dt,z8.),?yymmdd8.) > today() + 365

But those records with invalid A_COMM_DT values will be excluded by your WHERE clause because missing values are less than any valid value.

 

You should look at the observations with the invalid dates and decide what to do with them.

data check;
  set  VBM.INST_A;
  if missing(INPUT(PUT(A_COMM_DT,Z8.),??YYMMDD8.)) and not missing(A_COMM_DT) ;
run;

View solution in original post

8 REPLIES 8
AMSAS
SAS Super FREQ

Without knowing the A_COMM_DT values, it's hard to tell what is causing the error.

 

Still my guess is you have an A_COMM_DT value that doesn't fit the YYMMDD8. format e.g. 20210231 (no 31st of Feb)

 

The following will replicate your error

 

data have ;
	infile cards ;
	input a_comm_dt ;
cards ;
20230315
20230415
20230515
20230229
;

proc sql ;
	select 
		a_comm_dt as comm_dt
	from
		have
	where 
		input(put(a_comm_dt,z8.),yymmdd8.) > today() + 365 
	;
quit ;
Rixile106
Fluorite | Level 6

here are the values of A_COMM_DT

 

20220228
20210911

AMSAS
SAS Super FREQ
Are you sure? You only have 2 observations and those are the 2 values.
If you take those and drop them in the sample code (removing my bad 20230229 date) I supplied you'll see they work (at least they do for me).

Rixile106
Fluorite | Level 6
i have more than 200 observations, i was just showing you an example

20220228
20210911
20210911
20080901
20080128
20170925
20140830
20120728
20020528
20160902
20100413
20110209
20001017
20210101
20210625
20210801
20141028
20040720
20170729
20201201
20060601
20110127
20020829
20110831
20050103
19820809
20201120
20071027
20200229
20191225
20190120
20060627
20041228
20170227
20121030


AMSAS
SAS Super FREQ
Provide code and data to replicate the error, like I did.
Then we will be better able to help.
AMSAS
SAS Super FREQ

@Rixile106 You need to look at the values you have and check for invalid dates.
The error message is clear, it's telling you a date value in your data is not valid e.g. 20211301, 20210229, etc.

Could it be something else? Yes, but that is very unlikely.

I'd start with the obvious, go look at the data, specifically

  • Any rows where the day is 29|30|31 
  • Any months that are not 01-12 (the 0 needs to be there on the single digits)
Tom
Super User Tom
Super User

You can make the error MESSAGE go away by adding the ? modifier before the informat.

input(put(a_comm_dt,z8.),?yymmdd8.) > today() + 365

But those records with invalid A_COMM_DT values will be excluded by your WHERE clause because missing values are less than any valid value.

 

You should look at the observations with the invalid dates and decide what to do with them.

data check;
  set  VBM.INST_A;
  if missing(INPUT(PUT(A_COMM_DT,Z8.),??YYMMDD8.)) and not missing(A_COMM_DT) ;
run;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 8 replies
  • 3544 views
  • 2 likes
  • 3 in conversation