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.
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;
Simple, proc means expects a numeric variable. In your test data you are creating a character variable:
input ageyr:$3.;
^
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;
Is there any way to use the input function on its own variable without creating a new one? Thanks
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.