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

I try to count var1 when it is less than l_outlier however, the proc sql returns 1 in all cases 

 

this is table b 

var1 l_outlier l_outl_vol
1 5 1
2 1 1
3   1
4   1
5   1

 

i want the below. This is count var1 when it is less than l_outlier and not take in consideration the missing values 

 

var1 l_outlier l_outl_vol
1 5 1
2 1 0
3   0
4   0
5   0

 

 

data a;
    input var1 l_outlier;
    datalines;
1 5
2 1
3 .
4 .
5 .
;
run;

proc sql;
       create table b  as
       select *,
	   sum (case when  var1 < l_outlier then 1 else 0 end) as l_outl_vol
	   from a;
               quit;
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Remove SUM() from your PROC SQL. The SUM works over the entire data set, whereas you want the comparison to be on each row.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Remove SUM() from your PROC SQL. The SUM works over the entire data set, whereas you want the comparison to be on each row.

--
Paige Miller
andreas_lds
Jade | Level 19

No need for proc sql, just use a data step:

data want;
   set a;
   l_outl_vol = var1 < l_outlier;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1024 views
  • 3 likes
  • 3 in conversation