How can I resolve the error "The format of the input data does not match the expected format for the variable 'VariableName'" in SAS programming?
Thanks in advance
Without seeing the actual LOG, which shows code and error messages together, we can only guess. Please show us the entire log for this DATA step or PROC. Do not show us a part of the log for this PROC or DATA step. Please copy the log as text and paste it into the window that appears when you click on the </> icon.
Your input data is supposed to be (for example) a date, and its not. That's my guess.
Here is the SAS code snippet-
/* Create a sample input dataset */ data input_data; input VariableName $8.; datalines; 12345 ABCDE ; run; /* Attempt to read the input dataset with incorrect format */ data output_data; set input_data; length VariableName_num 8.; VariableName_num = input(VariableName, 8.); run;
I specifically asked to see the LOG
@raavichouhan wrote:
Here is the SAS code snippet-
/* Create a sample input dataset */ data input_data; input VariableName $8.; datalines; 12345 ABCDE ; run; /* Attempt to read the input dataset with incorrect format */ data output_data; set input_data; length VariableName_num 8.; VariableName_num = input(VariableName, 8.); run;
So what exactly is your question?
What number did you expect SAS to assign to VARIABLENAME_NUM when the value of variablename is 'ABCDE'?
'ABCDE' is very clearly not a number. What did you expect?
Have a go with the code below:
/* Create a sample input dataset */
data input_data;
input VariableName $8.;
datalines;
12345
ABCDE
;
run;
/* Attempt to read the input dataset with incorrect format */
data output_data;
set input_data;
length VariableName_num 8.;
VariableName_num = input(VariableName,?? 8.);
if (missing(VariableName_num)) then VariableName_num = ._;
run;
You really need to make sure that your examples relate to your actual question. You are asking about a message involving "expected format for the variable".
Your example does not generate such a message:(and an example of what a LOG looks like)
9 /* Attempt to read the input dataset with incorrect format */ 10 data output_data; 11 set input_data; 12 length VariableName_num 8.; 13 VariableName_num = input(VariableName, 8.); 14 run; NOTE: Invalid argument to function INPUT at line 13 column 22. VariableName=ABCDE VariableName_num=. _ERROR_=1 _N_=2 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 13:22 NOTE: There were 2 observations read from the data set WORK.INPUT_DATA. NOTE: The data set WORK.OUTPUT_DATA has 2 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds
The error above is that in the input value ABCDE in no way resembles a number and the INPUT function cannot read it as such given the 8. informat. But that is an Invalid data. Not "expected format" error message.
So, go back to the first request and show the LOG with the code and the specified error message so we can actually see what you did with the real problem.
@raavichouhan wrote:
Here is the SAS code snippet-
/* Create a sample input dataset */ data input_data; input VariableName $8.; datalines; 12345 ABCDE ; run; /* Attempt to read the input dataset with incorrect format */ data output_data; set input_data; length VariableName_num 8.; VariableName_num = input(VariableName, 8.); run;
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.