Hi All,
I was wondering if there is any way to convert the format of input variable in proc means from character to numeric without actually having to create the variable in the data-set.
This syntax won't work, but I want something like this:
PROC MEANS DATA=Cars;
var input(distance,best.);
run;
@sam_sas2 wrote:
Hi All,
I was wondering if there is any way to convert the format of input variable in proc means from character to numeric without actually having to create the variable in the data-set.
This syntax won't work, but I want something like this:
PROC MEANS DATA=Cars;
var input(distance,best.);
run;
Not possible.
You have to create the proper numeric variables in a DATA step before you run PROC MEANS.
That's a bummer.
I was hoping if we could create a user defined function and call it?
I don't know. I'm relatively new to SAS so..
You could do it in a view? A view is only run when you reference it so it's somewhat like having it done in the proc means step. Depending on what you're calculating you could also use SQL.
data temp/view=temp;
set have;
distance_num = input(distance, best.);
run;
In general though, I find it's worth the time to ensure my data is correctly read in and set up before I start doing any analysis. From a programming stand point its:
1. Import data
2. Clean
3. Explore
4. Analysis
5. Report
If during stage 3-5 I find a data issue such as this, I'll actually go back to Step 2 to fix it to ensure it flows through the rest of my programs and I'm not dealing with the same issue multiple times over.
SQL option:
proc sql;
create table want as
select class, mean(input(age, 8.)) as avg_age
from have
group by class;
quit;
It may help to provide an example of what your are attempting.
When you say Format and variable type, numeric or character, then you are saying the type of variable the format is applied to, not a result.
You can display any text for a given range of numeric values. Common: 1='Yes' 0='No'
or you can display Digits from a character variable.
Example:
proc format; value agerange 1-14 = '1 to 14' 15-high='15 plus' ; run; proc means data=sashelp.class; class age; format age agerange.; var height weight; run;
You have to associate the format with a variable. Since the calculated statistics above don't have a "variable" per se those are unlikely candidates for any custom formats at this stage.
A more concrete example with data and the type of output you want would be helpful.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.