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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 874 views
  • 1 like
  • 2 in conversation