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

I have the following:

 

data have;
  input Sl  Return;
datalines;
 1  4.5563
 2  4.8562
 3  0.0000
 4  3.5879
 5  0.0000
 6  0.0000
 7  0.0000
 8  0.0000
 9  2.5879
10  3.6879
run;

I know I can use PROC SQL to count observations, but I would need to do the same in a DATA step. I want:

 

DATA want;

set HAVE;

 

count number of observations if return= 0;

zero_ret_perc= (number of observations with zero returns/ total number of observations)*100;

run;

 

How can I achieve this?

 

Much thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data have;
  input Sl  Return;
datalines;
 1  4.5563
 2  4.8562
 3  0.0000
 4  3.5879
 5  0.0000
 6  0.0000
 7  0.0000
 8  0.0000
 9  2.5879
10  3.6879
run;


data want;
set have nobs=nobs end=lr;
zero_ret+ return=0;
if lr;
zero_ret_perc= (zero_ret/nobs)*100;
run;

View solution in original post

1 REPLY 1
novinosrin
Tourmaline | Level 20
data have;
  input Sl  Return;
datalines;
 1  4.5563
 2  4.8562
 3  0.0000
 4  3.5879
 5  0.0000
 6  0.0000
 7  0.0000
 8  0.0000
 9  2.5879
10  3.6879
run;


data want;
set have nobs=nobs end=lr;
zero_ret+ return=0;
if lr;
zero_ret_perc= (zero_ret/nobs)*100;
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1266 views
  • 1 like
  • 2 in conversation