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 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!

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
  • 950 views
  • 1 like
  • 2 in conversation