BookmarkSubscribeRSS Feed
raavichouhan
Fluorite | Level 6

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

Thanks
Ravikant Chouhan
Splunk Certification
7 REPLIES 7
PaigeMiller
Diamond | Level 26

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.

2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png

 

Your input data is supposed to be (for example) a date, and its not. That's my guess.

--
Paige Miller
raavichouhan
Fluorite | Level 6

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;

 

Thanks
Ravikant Chouhan
Splunk Certification
PaigeMiller
Diamond | Level 26

I specifically asked to see the LOG

--
Paige Miller
Tom
Super User Tom
Super User

@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'?

JosvanderVelden
SAS Super FREQ

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;
ballardw
Super User

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;

 


 

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
  • 7 replies
  • 844 views
  • 2 likes
  • 6 in conversation