BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aminkarimid
Lapis Lazuli | Level 10

hello everybody.

I want to convert date character type to numeric. I use a code which is shown below.

data Sampledata;
	set table01 table02;
	new_var = input(TRD_EVENT_DT,mmddyy10.);
	format new_var date9.;
	drop TRD_EVENT_DT;
	rename new_var = TRD_EVENT_DT;
run;

The log file is:

NOTE: Invalid argument to function INPUT at line 938 column 15.
TRD_EVENT_DT=2014-03-25 TRD_EVENT_TM=11:36:35 TRD_STCK_CD=PNLZ1 TRD_PR=22200 TRD_TUROVR=2400 new_var=.
_ERROR_=1 _N_=1
NOTE: Invalid argument to function INPUT at line 938 column 15.
TRD_EVENT_DT=2014-03-25 TRD_EVENT_TM=11:37:17 TRD_STCK_CD=PNLZ1 TRD_PR=22210 TRD_TUROVR=50 new_var=.
_ERROR_=1 _N_=2
NOTE: Invalid argument to function INPUT at line 938 column 15.
TRD_EVENT_DT=2014-03-25 TRD_EVENT_TM=11:37:17 TRD_STCK_CD=PNLZ1 TRD_PR=22202 TRD_TUROVR=50 new_var=.
_ERROR_=1 _N_=3
NOTE: Invalid argument to function INPUT at line 938 column 15.
TRD_EVENT_DT=2014-03-25 TRD_EVENT_TM=11:38:09 TRD_STCK_CD=PNLZ1 TRD_PR=22230 TRD_TUROVR=500 new_var=.
_ERROR_=1 _N_=4
NOTE: Invalid argument to function INPUT at line 938 column 15.
TRD_EVENT_DT=2014-03-25 TRD_EVENT_TM=11:38:09 TRD_STCK_CD=PNLZ1 TRD_PR=22200 TRD_TUROVR=1434 new_var=.
_ERROR_=1 _N_=5
NOTE: Mathematical operations could not be performed at the following places. The results of the
      operations have been set to missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      17976342 at 938:15
NOTE: There were 10000000 observations read from the data set WORK.TABLE01.
NOTE: There were 7976342 observations read from the data set WORK.TABLE02.
NOTE: The data set WORK.SAMPLEDATA has 17976342 observations and 5 variables.

What is the problem?

How can I fix that?

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

For starters your date looks like:

TRD_EVENT_DT=2014-03-25

While you've specified an informat of:

 

mmddyy10.

Which is month, day, year. Yours is clearly yymmdd

 

There's possibly other issues, but you should probably fix that first.  I would remove the rename until it works and then do it after. It's usually easier and cleaner IMO to rename the variable on input, create the new variable with the old name and then drop the old variable. 

View solution in original post

2 REPLIES 2
Reeza
Super User

For starters your date looks like:

TRD_EVENT_DT=2014-03-25

While you've specified an informat of:

 

mmddyy10.

Which is month, day, year. Yours is clearly yymmdd

 

There's possibly other issues, but you should probably fix that first.  I would remove the rename until it works and then do it after. It's usually easier and cleaner IMO to rename the variable on input, create the new variable with the old name and then drop the old variable. 

kiranv_
Rhodochrosite | Level 12

use 

new_var = input(myvar,yymmdd10.);

 

 

and do not forget to format as below or whatever you like

 

format new_var mmddyy10.;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 2 replies
  • 30333 views
  • 1 like
  • 3 in conversation