BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mona4u
Lapis Lazuli | Level 10

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
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

6 REPLIES 6
novinosrin
Tourmaline | Level 20

filter using 

where anyalpha(var)=0;
mona4u
Lapis Lazuli | Level 10

this code isn't working 

novinosrin
Tourmaline | Level 20

post your code and log please

ballardw
Super User

@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.

Astounding
PROC Star

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

Reeza
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

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
  • 6 replies
  • 1121 views
  • 6 likes
  • 5 in conversation