DATA Step, Macro, Functions and more

proc means

Accepted Solution Solved
Reply
Regular Contributor
Posts: 158
Accepted Solution

proc means

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

Accepted Solutions
Highlighted
Solution
‎02-16-2018 11:41 AM
Super User
Posts: 6,753

Re: proc means

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.);

View solution in original post


All Replies
PROC Star
Posts: 1,770

Re: proc means

filter using 

where anyalpha(var)=0;
Regular Contributor
Posts: 158

Re: proc means

Posted in reply to novinosrin

this code isn't working 

PROC Star
Posts: 1,770

Re: proc means

post your code and log please

Super User
Posts: 13,507

Re: proc means


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.

Highlighted
Solution
‎02-16-2018 11:41 AM
Super User
Posts: 6,753

Re: proc means

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.);

Super User
Posts: 23,677

Re: proc means

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 316 views
  • 6 likes
  • 5 in conversation