BookmarkSubscribeRSS Feed
JUMMY
Obsidian | Level 7
proc means data=merge_bcbs N MEAN STDDEV MEDIAN MAX MIN maxdec=4;
	var type srxtype_n antif fracture;
			title '';
run;
400  proc means data=merge_bcbs N MEAN STDDEV MEDIAN MAX MIN maxdec=4;
401      var type;
402              title '';
403  run;

NOTE: There were 100 observations read from the data set WORK.MERGE_BCBS.
NOTE: PROCEDURE MEANS used (Total process time):
      real time           0.03 seconds
      cpu time            0.03 seconds


404  proc means data=merge_bcbs N MEAN STDDEV MEDIAN MAX MIN maxdec=4;
405      var type srxtype_n antif fracture;
ERROR: Variable srxtype_n in list does not match type prescribed for this list.
ERROR: Variable antif in list does not match type prescribed for this list.
ERROR: Variable fracture in list does not match type prescribed for this list.
406              title '';
407  run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE MEANS used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

 

I am trying calculate descriptive statistics on all variables I created (inserted above in proc step). I keep getting an error message that the variable does not match the prescribed list. Most of my variables are character. How do I run proc means on character variables. IS there a way to convert it to numeric? What am I doing wrong? 

10 REPLIES 10
Reeza
Super User

You can't compute statistics on  a character variable. SAS likely read a column in as character, when you want it as numeric. 

Run a PROC CONTENTS and check your variable types.

 


@JUMMY wrote:
proc means data=merge_bcbs N MEAN STDDEV MEDIAN MAX MIN maxdec=4;
	var type srxtype_n antif fracture;
			title '';
run;
400  proc means data=merge_bcbs N MEAN STDDEV MEDIAN MAX MIN maxdec=4;
401      var type;
402              title '';
403  run;

NOTE: There were 100 observations read from the data set WORK.MERGE_BCBS.
NOTE: PROCEDURE MEANS used (Total process time):
      real time           0.03 seconds
      cpu time            0.03 seconds


404  proc means data=merge_bcbs N MEAN STDDEV MEDIAN MAX MIN maxdec=4;
405      var type srxtype_n antif fracture;
ERROR: Variable srxtype_n in list does not match type prescribed for this list.
ERROR: Variable antif in list does not match type prescribed for this list.
ERROR: Variable fracture in list does not match type prescribed for this list.
406              title '';
407  run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE MEANS used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

 

I am trying calculate descriptive statistics on all variables I created (inserted above in proc step). I keep getting an error message that the variable does not match the prescribed list. What am I doing wrong? 


 

PeterClemmensen
Tourmaline | Level 20

Please run

 

proc contents data=merge_bcbs;
run;

What types of variables are these?

JUMMY
Obsidian | Level 7
@PeterClemmensen. they are character variables. Is there a way to convert them to numeric and then do a proc means?
mkeintz
PROC Star

It appears that the unprocessed variables are of type character, not type numeric.  Proc means is intended to generates stats only for numeric variables.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
JUMMY
Obsidian | Level 7
@mkeintz, they are character variables. Is there a way to convert them to numeric and then do a proc means?
mkeintz
PROC Star

If they are character variables, let's assume they contain nothing but blanks, contiguous numeric characters, and maybe one decimal point.  One can deal with fancier character vars (say with currency symbols, commas, etc.) but the point here is to demonstrate the INPUT function, usually (but not exclusively) used to convert a character value into a numeric value:

 

data vneed / view=vneed;
  set have (rename=(srxtype_n=chrv1 antif=chrv2 fracture=chrv3));
  srxtype_n=input(chrv1,best32.);
  antif_n=input(chrv2,best32.);
  fracture_n=input(chrv3,best32.);
  put (_character_) (=) / (_numeric_) (=);
run;

proc means data=vneed;
  var ...... ;
run;

 

A couple of notes:

  1. YOu can't convert a character variable to a numeric variable.  I.e. a variable can only be one type for the duration of a data step.  That's why I did renames of the character variables above.  Then when the INPUT function was run, I could re-use the original variable names that you probably want to use in the proc means.
  2. The input function needs 2 arguments, the character variable name, and the format to apply.  I suspect that best32. format will serve your needs.
  3. (edited additional note).  Also, for efficiency's sake I made VNEED a data set "view", not a data set "file".  Assuming you don't need the numeric conversion to be permanent, there is no need to write data set need to a disk only to re-read it once.  A data set view avoids that process - instead it read from the original data set (HAVE), and transfers the content of data set need, one record at a time, to the proc means.
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
JUMMY
Obsidian | Level 7
@mkeintz, I am a new sas user. Pardon me. So what variables do I put under proc means?
mkeintz
PROC Star

That's a question easily answered by (1) reading one of @Reeza's comments, or (2) experimenting (which I believe all programmers do - so welcome to the club).

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ballardw
Super User

@JUMMY wrote:
@mkeintz, they are character variables. Is there a way to convert them to numeric and then do a proc means?

Go back to when you read the data into SAS. Read the values as intended. If the source data was Excel convert to CSV first.

With CSV you can use Proc Import option guessingrows to read more rows before guessing the variable type, use a large value such as 32000.

Or write a data step or modify the data step code created by Proc Import, copy from the log and edit.

Reeza
Super User
And if you exclude a VAR statement entirely, SAS will run it for all numeric variables by default.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 10 replies
  • 1620 views
  • 3 likes
  • 5 in conversation