BookmarkSubscribeRSS Feed
gtucke1
Fluorite | Level 6

I'm still confused about changing education (edu) and caregiver education (cg_edu)  variable in number of years from character to numeric value. The data set I was given was in SPSS. I imported it as SAS. When I run a proc means on edu, I receive the following error:

 

ERROR: Variable edu in list does not match type prescribed for this list. 

ERROR: Variable cg_edu in list does not match type prescribed for this list. 

 

From watching SAS videos and reading SAS how to and some earlier responses to me in SAS communities, I know there is a way to use an input or put statement. I cannot figure out how to apply this with my data.

 

When I run a proc contents:

edu is listed as a character value, Len = 2 and Format = $2.

cg_edu is listed as a character value, Len = 12 Format = F12.

 

I'm not sure what format to put in the INPUT statement for edu and cg_edu.

 

Data Sunday;

Set Monday;

edu_numeric = INPUT (edu, format?);

cg_edu_numeric = INPUT (cg_edu, format?);

Run;

 



4 REPLIES 4
PaigeMiller
Diamond | Level 26

When you get errors in the log, show us the ENTIRE log for that data step (or PROC). Do not show us just the errors. Copy and paste the ENTIRE log for that data step (or PROC) into the window that appears when you click on the </> icon.

Insert Log Icon in SAS Communities.png

 

Also, please show us what PROC CONTENTS says for EDU and CG_EDU, and please show us typical values for these two variables.

--
Paige Miller
Tom
Super User Tom
Super User

The TYPE of the variable is much more important than the LENGTH or any FORMAT that might or might not be attached to it.

 

What you show is not possible:

edu is listed as a character value, Len = 2 and Format = $2.

cg_edu is listed as a character value, Len = 12 Format = F12.

For CQ_EDU to be numeric the maximum storage length it could have is 8.  That is because SAS stores all numeric variables as 64-bit floating point numbers.  You can store them with less than the full 8 bytes (with the corresponding loss of precision in representing the values) but not with more.  But if it is character with a length of 12 then you could NOT use the numeric format F12. with that variable.  The type of the format has to match the type of the variable (or value) it is being used to format (aka print as text).

 

So the key thing to look for in the output from PROC CONTENTS it the TYPE of the variable.  For example here is the output for SASHELP.CLASS.

Tom_0-1662915838658.png

As you can see two of the variables are character and the other three are numeric.  Notice also that none of them have a FORMAT attached to them.  That is because SAS does not need any special instructions to display character strings or numbers.  Even the non-integer values of HEIGHT and WEIGHT.  For most outputs SAS will default to using the BEST12. format to display numbers.  The BEST format tries to find the best way to represent the value (print the value) in the fixed number of characters specified by the width of the format specification.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 589 views
  • 0 likes
  • 4 in conversation