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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 528 views
  • 3 likes
  • 3 in conversation