I have a numeric variable which includes some written characteristics parts like the following
the problem is I need to calculate some statistics for the variable by proc mean and it doesn't let me bc of the written characteristic part. this is the error that I got
Variable site_number in list does not match type prescribed for this list
I need a way to ask sas to ignore the written part and just calculate the numeric
or substr the numeric part
1453 |
1500 |
1600 |
1601 |
1602 |
1700 |
1750 |
5000 |
5002 |
5003 Main Campus |
5003 Burbank |
PROC MEANS does not compute statistics for character variables. You need to create a new variable, make it numeric, and have it contain the numeric piece of SITE_NUMBER. For example:
data want;
set have;
newvar = input( compress(site_number, , 'kd' ), 5.);
run;
Then you can process the new variable with PROC MEANS.
If the numeric portion is always the first four or five characters of SITE_NUMBER, the formula can be simplified:
newvar = input(site_number, 5.);
filter using
where anyalpha(var)=0;
this code isn't working
post your code and log please
@mona4u wrote:
this code isn't working
Doesn't work is awful vague.
Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.
No output? Post any log in a code box.
Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
PROC MEANS does not compute statistics for character variables. You need to create a new variable, make it numeric, and have it contain the numeric piece of SITE_NUMBER. For example:
data want;
set have;
newvar = input( compress(site_number, , 'kd' ), 5.);
run;
Then you can process the new variable with PROC MEANS.
If the numeric portion is always the first four or five characters of SITE_NUMBER, the formula can be simplified:
newvar = input(site_number, 5.);
You need to clean your data before you analyze it. With the data in the form shown, I suspect it was not read in correctly to start.
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.