BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Barite | Level 11

Hi Everyone,

I have value file having 1 variable "value" and a level file which has different level.

I want to create a new file that count the number of record in value file that fall in the range specified in level file.

For the data below, the range [-1  to 0.5] has 4 record; [0.5 to 1.5] has 1 record; [1.5 to 2.5] has 1 record.

Thank you for your help.

HHC

data value;

input value;

datalines;

-0.2

-0.3

-0.5

0.2

2.3

1.3

;

data level;

input lv1 lv2 lv3 lv4 lv5;

datalines;

-1 0.5 1.5  2.5 3.0

;run;

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

data value;
input value;
datalines;
-0.2
-0.3
-0.5
0.2
2.3
1.3
;

data level;
input lv1 lv2 lv3 lv4 lv5;
datalines;
-1 0.5 1.5  2.5 3.0
;

proc sql;
create table have as
select * from value,level;
quit;

data want(drop=i);
set have;
array l{*} lv1-lv5;
array r{*} range1 range2 range3 range4;
do i=1 to dim(l);
if value>=l{i} and value<=l{i+1} then r{i}=1;
end;
run;


proc freq data=want;
table r:;
run;

View solution in original post

1 REPLY 1
stat_sas
Ammonite | Level 13

data value;
input value;
datalines;
-0.2
-0.3
-0.5
0.2
2.3
1.3
;

data level;
input lv1 lv2 lv3 lv4 lv5;
datalines;
-1 0.5 1.5  2.5 3.0
;

proc sql;
create table have as
select * from value,level;
quit;

data want(drop=i);
set have;
array l{*} lv1-lv5;
array r{*} range1 range2 range3 range4;
do i=1 to dim(l);
if value>=l{i} and value<=l{i+1} then r{i}=1;
end;
run;


proc freq data=want;
table r:;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 365 views
  • 0 likes
  • 2 in conversation