BookmarkSubscribeRSS Feed
kajal_30
Quartz | Level 8

I have a data set where 

date = 30apr2020

I want to use this date to create another variable as 

datez = INPUT(PUT(18000000+date,z8.),yymmdd8.);

 

I am getting error as invalid argument to function input.Can you please help if I need to convert the value of date first then use in datez ?

 

 

22 REPLIES 22
Reeza
Super User
What is the type and format on the data?
kajal_30
Quartz | Level 8

format for the date is 8. , Informat date9., type number , length 8 

ChrisNZ
Tourmaline | Level 20

>format for the date is 8. , Informat date9., type number , length 8 

This makes no sense whatsoever.

What are you trying to achieve?

At the moment, the code you are trying to run adds 18 million days to that date.

Maybe this is a datetime.

data HAVE;
  DATE  = '30apr2020:0:0'dt;
  DATEZ = 18000000+DATE;
  putlog DATEZ= datetime20.;
run;

DATEZ=24NOV2020:08:00:00
But this is still extremely odd. What on earth is the goal?

 

 

 

Tom
Super User Tom
Super User

@kajal_30 wrote:

format for the date is 8. , Informat date9., type number , length 8 


So what kind of values does it have?  It obviously cannot have the value you mentioned in your original post.  For it to have a valid that looked like 30APR2020 it would either have to be a character variable with a length of at least 9 bytes.  Or it would have to have the value of 22,035 (the date value corresponding to that date) and have the DATE9. format attached to it instead of the F8. format you listed.

Is it possible you have integers where the digits look like C,YYM,MDD?  Where C is zero for 1800's , 1 for 1900's, 2 for 2000's, 3 for 2100's, etc.  But in that case why does it have the INFORMAT of DATE attached to it?  Not that informats have much impact on a dataset since they are just instructions for how to convert text to values and once you have a dataset you already have the values stored and are no longer converting from text.

 

If your conversion program makes some sense you also need to attach a date type format to the new variable or you will get the raw number of days printed instead of a human readable date representation.  

kajal_30
Quartz | Level 8
Can we get on a call or zoom meeting I am totally stuck.As the code I posted is running fine and expected from last 10 years.
kajal_30
Quartz | Level 8
I think the logic you described here is exactly what the code is doing.Even if I am able to calculate numeric value of date But still I am not sure why code is not able to add numeric value of date to 18000000 ?
let say I calculated value of date as 22083 but still it throws error if I submit below code.
datez = INPUT(PUT(18000000+date,z8.),yymmdd8.);
Please help and let me know what wrong am I doing here?
Reeza
Super User

What EXACTLY does your date variable look like? Please review Tom's message and address his comments otherwise we really have no idea what's going on here. 

 

Has nothing else changed? Are you sure your data is being read in the same way it was historically?

Clearly something isn't working as expected, but I also suspect you're running code you don't fully understand. 

kajal_30
Quartz | Level 8
I think the logic you described here is exactly what the code is doing.Even if I am able to calculate numeric value of date But still I am not sure why code is not able to add numeric value of date to 18000000 ?
let say I calculated value of date as 22083 but still it throws error if I submit below code.
datez = INPUT(PUT(18000000+date,z8.),yymmdd8.);
Please help and let me know what wrong am I doing here?
Patrick
Opal | Level 21

Please post the actual code you're running and especially the log where the error shows up.

Just writing "still throws an error" doesn't help much. Also make sure that you look at the very first Warnings and especially Errors in your code and resolve these first.

Reeza
Super User
I strongly suspect how you read the date variable has changed somewhere upstream and your code isn't accounting for it correctly anymore.
Reeza
Super User

Your code doesn't work because of the INPUT(). 

 

INPUT() is expecting a date in the format of yymmdd but after you add 18000000 to your number you do not end up with a character string that looks like a date so it cannot be read in correctly. 

 

Here's a fully worked example illustrating the issue. Line 78 illustrates the issue for you. Check the log. 

 

 69         data have;
 70         date = '30Apr2009'd;
 71         datez = INPUT(PUT(18000000+date,z8.),yymmdd8.);
 72         
 73         put "date= " date;
 74         put "datez= " datez;
 75         
 76         part1 = PUT(18000000+date,z8.);
 77         put "Part 1: " part1;
 78         part2 = input(part1, yymmdd8.);
 79         put "Part 2: " part2;
 80         
 81         run;
 
 NOTE: Invalid argument to function INPUT at line 71 column 9.
 date= 18017
 datez= .
 Part 1: 18018017
 NOTE: Invalid argument to function INPUT at line 78 column 9.
 Part 2: .
 date=18017 datez=. part1=18018017 part2=. _ERROR_=1 _N_=1
 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).
       1 at 71:9   1 at 78:9   
 NOTE: The data set WORK.HAVE has 1 observations and 4 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds

18018017 -> YYMMDD doesn't align unless that's 1801, 80 month which I don't know what that means and 17 days is valid.  

kajal_30
Quartz | Level 8

The code I am running is a main frame code which I am trying to convert to a base sas

Reeza
Super User
Seriously? Is the code erroring on the mainframe or base?

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
  • 22 replies
  • 1844 views
  • 5 likes
  • 6 in conversation