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 ?
format for the date is 8. , Informat date9., type number , length 8
>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?
@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.
Sorry, but with the data you described, that code is useless. It is designed for a numeric value that is not a SAS date at all.
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.
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.
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.
The code I am running is a main frame code which I am trying to convert to a base sas
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.