BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
byeh2017
Quartz | Level 8

I'm trying to get some descriptive stats from an age variable in my dataset. I am using this simple code:

 

proc means data=janfeb.sampleage;
var ageyr;
run;

However, I'm getting this error:

 

 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 61         
 62         proc means data=janfeb.sampleage;
 63         var ageyr;
 ERROR: Variable ageyr in list does not match type prescribed for this list.
 64         run;
 
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE MEANS used (Total process time):
       real time           0.02 seconds
       cpu time            0.02 seconds
       
 65         
 66         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 79         

Here is a sample dataset I'm using:

data JANFEB.SAMPLEAGE;
  infile datalines dsd truncover;
  input ageyr:$3.;
datalines4;
75
81
72
75
65
64
80
67
66
66
62
70
72
60
60
67
89
79
75
77
60
62
65
85
64
64
64
68
68
61
79
78
82
61
61
80
77
74
70
85
77
73
72
65
64
60
79
62
73
76
74
72
68
60
67
61
83
61
77
60
71
68
65
86
69
75
61
75
64
79
64
71
69
63
83
83
72
65
60
75
60
79
76
73
68
78
61
78
61
74
61
80
74
62
81
79
64
79
71
69
;;;;

Not sure what is going on, appreciate the help. Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

If your reading it in, then:

data JANFEB.SAMPLEAGE;
  infile datalines dsd truncover;
  input ageyr;
datalines4;
75
81
...
;

If it already exists, use input() function:

data want;
  set have;
  num_var=input(ageyr,best.);
run;

View solution in original post

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Simple, proc means expects a numeric variable.  In your test data you are creating a character variable:

  input ageyr:$3.;
^

 

byeh2017
Quartz | Level 8
On another dataset, how do i convert this variable into numeric only?

##- Please type your reply above this line. Simple formatting, no
attachments. -##
RW9
Diamond | Level 26 RW9
Diamond | Level 26

If your reading it in, then:

data JANFEB.SAMPLEAGE;
  infile datalines dsd truncover;
  input ageyr;
datalines4;
75
81
...
;

If it already exists, use input() function:

data want;
  set have;
  num_var=input(ageyr,best.);
run;
byeh2017
Quartz | Level 8

Is there any way to use the input function on its own variable without creating a new one? Thanks

RW9
Diamond | Level 26 RW9
Diamond | Level 26

No, you can't put numeric data into a character variable.  So if you tried:

char_var=input("01",best.);

The return would be:

char_var=01;

And as char_var is character, it would implicitly change 01 to be "01", back to your issue again.  Hence why datatypes are important, if you have numeric data keep it as numeric.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 3881 views
  • 1 like
  • 2 in conversation