SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I want to check my data if it exists between ranges. Say for example my data is coming as decimals ranging 0.00 to 220.90 then if want to check data if first 3 bytes before decimals in range 140 - 150 and then last two bytes after decimals b/w 80 -89 , how to do this in data step statement.

compress decimals and then use if then else??

Please let me know soon.

thanks,
sasbase
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Depends on your SAS variable, whether it is character or numeric type. If character type, recommend converting it to a numeric variable (different name) using the INPUT function, and then do your comparison, doing so in a SAS DATA step. I have provided a link below to a SAS SUG/SGF user community paper which discusses INPUT function and data variable conversion. There are others like this, available by searching at the SAS support website http://support.sas.com/ .

Scott Barry
SBBWorks, Inc.


http://www2.sas.com/proceedings/sugi26/p056-26.pdf
deleted_user
Not applicable
Have you considered using formats, something along these lines:

data have;
input val;
cards;
1
20.5
30.9
140.0
145.2
145.85
200
;
run;

proc format;
value intPart
low - 139.99 = 'Low '
140 - 149.99 = 'Want'
150 - high = 'High'
;
run;

proc format;
value decPart
low - 0.79 = 'Low '
0.8 - 0.89 = 'Want'
0.9 - high = 'High'
;
run;

data want;
set have;
intRange = put(val, intPart.);
decRange = put(val - int(val), decPart.);
run;

proc sql;
create table summary
as
select intRange, decRange, count(val) as count
from want
group by 1,2
;
quit;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1212 views
  • 0 likes
  • 2 in conversation