My date of arrivals are in $11. Any ideas how to change it back to the original numeric date? Either mmddyy10 or ddmmyy10? I've tried so many input functions and it says it's invalid.
Data have;
arrival_date
01/03/2018
02/03/2019
data want;
arrival_date_
01/03/2019 (numeric)
02/03/2019 (numeric)
You need to use the SAS format that matches the form of the character variable. Something like this:
data have;
input date $15.;
cards;
01/03/2018
02/03/2019
;
run;
data want;
set have;
x = input(date, MMDDYY10.);
putlog _all_;
run;
This site has the information: https://sasexamplecode.com/how-to-easily-convert-a-string-into-a-date-in-sas/
data want;
set have;
arrival_date_=input(arrival_date,ddmmyy10.);
run;
I tried this and it sets my new date variable to missing and says
NOTE: Invalid argument to function INPUT at line 24 column 16.
Hi:
With the INPUT function, mmddyy10. worked for me, as shown below:
Note that the date value is internally stored as the number of days since Jan 1, 1960, so the internally stored value will ALWAYS be a number, not a formatted value. But you can designate a format to use. So the output in the log shows how the variable NUMDATE is internally stored and then also shows how to use 2 different SAS date formats in order to display that date value as a readable date.
Cynthia
Note that using either MDY or DMY order for dates will confuse 50% of your audience.
Is '01/03/2018' the First of March or January Third?
data want;
set have;
arrival_date_ = input(arrival_date,mmddyy10.);
format arrival_date_ yymmdd10.;
run;
I tried this and it sets the new variable to missing and says,
"NOTE: Invalid argument to function INPUT at line 24 column 16."
@stancemcgraw wrote:
I tried this and it sets the new variable to missing and says,
"NOTE: Invalid argument to function INPUT at line 24 column 16."
Provide the entire log, not just pieces. That note usually has a how many times this occurred which is important. You should include ALL of the code for the data step and ALL the messages from the log. Copy the text from the log and open a text box on the forum using the </> icon above the message window, the paste the text.
The entire log with all the notes is important. One the code tells exactly what you submitted. If the Note also includes the invalid data description, or typically up to 20 by default, then we can see exactly what the incorrect values involved were.
Example (which is stupid because it attempts to turn a persons name into a date). So the copied LOG text shows the actual text of code. So we get invalid data messages we can see exactly the code that causes the problem and no what line 166 looks like.
Next every one of those notes up to a moderately esoteric system setting shows the values of the variables in the data set at the time the invalid data is encountered. So we look at column 17 (which is why you want to paste the text in a code box. The message windows can reformat text to remove spaces) which is the first character of INPUT (not surprising with this code but it may have involved a different function). Then we look at the invalid data and the variables that are involved starting at column 17. The only one is Name. The input we used with DATE7 expects to see a value like 15Jul22. Of course none of the names look like that. But it is important to diagnose your problem. The _n_= at the end is important, that is basically the line in the data with simple code. If you see sequential numbers it is often an indicator that your code is wrong, such as incorrect format for the text. If you see values at random then there may be problems with the text of a date intermittently. Dates are notorious when data is manually entered into a system that doesn't do good validation for having values like 30FEB, 31JUN and such. I had one project I inherited a 30 year old data set with a day 67 in November.
A likely problem is misunderstanding what digits in your data mean because there are common date structures that start with the day of the month, the month of the year or the year. If you use the wrong one you will have problems. But since you have provided no actual statement that your data is in Month/day/year or Day/month/year order you may have copied one that does not align with your actual data.
And then there are the data sources that will have multiple formats such as just a month and year or just a year sometimes. So we need to see the actual type of problems you are having to suggest an actual solution.
164 data junk; 165 set sashelp.class; 166 stupiddate = input(name,date7.); 167 run; NOTE: Invalid argument to function INPUT at line 166 column 17. Name=Alfred Sex=M Age=14 Height=69 Weight=112.5 stupiddate=. _ERROR_=1 _N_=1 NOTE: Invalid argument to function INPUT at line 166 column 17. Name=Alice Sex=F Age=13 Height=56.5 Weight=84 stupiddate=. _ERROR_=1 _N_=2 NOTE: Invalid argument to function INPUT at line 166 column 17. Name=Barbara Sex=F Age=13 Height=65.3 Weight=98 stupiddate=. _ERROR_=1 _N_=3 NOTE: Invalid argument to function INPUT at line 166 column 17. Name=Carol Sex=F Age=14 Height=62.8 Weight=102.5 stupiddate=. _ERROR_=1 _N_=4 NOTE: Invalid argument to function INPUT at line 166 column 17. Name=Henry Sex=M Age=14 Height=63.5 Weight=102.5 stupiddate=. _ERROR_=1 _N_=5 NOTE: Invalid argument to function INPUT at line 166 column 17. Name=James Sex=M Age=12 Height=57.3 Weight=83 stupiddate=. _ERROR_=1 _N_=6 NOTE: Invalid argument to function INPUT at line 166 column 17. Name=Jane Sex=F Age=12 Height=59.8 Weight=84.5 stupiddate=. _ERROR_=1 _N_=7 NOTE: Invalid argument to function INPUT at line 166 column 17. Name=Janet Sex=F Age=15 Height=62.5 Weight=112.5 stupiddate=. _ERROR_=1 _N_=8 NOTE: Invalid argument to function INPUT at line 166 column 17. Name=Jeffrey Sex=M Age=13 Height=62.5 Weight=84 stupiddate=. _ERROR_=1 _N_=9 NOTE: Invalid argument to function INPUT at line 166 column 17. Name=John Sex=M Age=12 Height=59 Weight=99.5 stupiddate=. _ERROR_=1 _N_=10 NOTE: Invalid argument to function INPUT at line 166 column 17. Name=Joyce Sex=F Age=11 Height=51.3 Weight=50.5 stupiddate=. _ERROR_=1 _N_=11 NOTE: Invalid argument to function INPUT at line 166 column 17. Name=Judy Sex=F Age=14 Height=64.3 Weight=90 stupiddate=. _ERROR_=1 _N_=12 NOTE: Invalid argument to function INPUT at line 166 column 17. Name=Louise Sex=F Age=12 Height=56.3 Weight=77 stupiddate=. _ERROR_=1 _N_=13 NOTE: Invalid argument to function INPUT at line 166 column 17. Name=Mary Sex=F Age=15 Height=66.5 Weight=112 stupiddate=. _ERROR_=1 _N_=14 NOTE: Invalid argument to function INPUT at line 166 column 17. Name=Philip Sex=M Age=16 Height=72 Weight=150 stupiddate=. _ERROR_=1 _N_=15 NOTE: Invalid argument to function INPUT at line 166 column 17. Name=Robert Sex=M Age=12 Height=64.8 Weight=128 stupiddate=. _ERROR_=1 _N_=16 NOTE: Invalid argument to function INPUT at line 166 column 17. Name=Ronald Sex=M Age=15 Height=67 Weight=133 stupiddate=. _ERROR_=1 _N_=17 NOTE: Invalid argument to function INPUT at line 166 column 17. Name=Thomas Sex=M Age=11 Height=57.5 Weight=85 stupiddate=. _ERROR_=1 _N_=18 NOTE: Invalid argument to function INPUT at line 166 column 17. Name=William Sex=M Age=15 Height=66.5 Weight=112 stupiddate=. _ERROR_=1 _N_=19 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). 19 at 166:17 NOTE: There were 19 observations read from the data set SASHELP.CLASS. NOTE: The data set WORK.JUNK has 19 observations and 6 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
@stancemcgraw wrote:
I tried this and it sets the new variable to missing and says,
"NOTE: Invalid argument to function INPUT at line 24 column 16."
So perhaps the answer to my question was that it was the First of March and not January Third.
Did you try using DDMMYY as the informat instead of MMDDYY?
Or perhaps there are just some values that are blank? You could try only trying to create a date when the string is not empty.
it not missing(arrival_date) then arrival_date_ = input(arrival_date,mmddyy10.);
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.