Help using Base SAS procedures

Numbers stored as Char Variables & Their Magnitude

Reply
Frequent Contributor
Posts: 75

Numbers stored as Char Variables & Their Magnitude

I have

 

'1', '2', '3',... stored as a Character variable - Types

 

If i want to subset a dataset

 

if Types <='10'

 

will it select all values from '1',....'10'?

 

In other words, does SAS interpret the magnitude of numbers stored as character variable in the same way as  numeric variable?

 

Thank you

Respected Advisor
Posts: 3,900

Re: Numbers stored as Char Variables & Their Magnitude

No it doesn't. It compares character by character. You need to convert your characters to numeric for such a comparison.

23 data _null_;
24 types='2';
25 if types<='10' then put 'TRUE';
26 else put 'FALSE';
27
28 if input(types,best32.)<=10 then put 'TRUE';
29 else put 'FALSE';
30
31 run;

FALSE
TRUE

 

 

Ask a Question
Discussion stats
  • 1 reply
  • 213 views
  • 0 likes
  • 2 in conversation