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;
Remove SUM() from your PROC SQL. The SUM works over the entire data set, whereas you want the comparison to be on each row.
Remove SUM() from your PROC SQL. The SUM works over the entire data set, whereas you want the comparison to be on each row.
No need for proc sql, just use a data step:
data want;
set a;
l_outl_vol = var1 < l_outlier;
run;
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!
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.
Ready to level-up your skills? Choose your own adventure.