BookmarkSubscribeRSS Feed
d6k5d3
Pyrite | Level 9

I am trying to understand how the code runs in the loop to generate the desired outcome:

 

data Zero_Returns; *calculating number of incidents of zero returns everyday;
set HUF;			*and number of zero returns in each of those incidents;
by Date Return notsorted;

if first.Date then Incident_No= 0;
if first.Return then Consecutive_Zero= 1;
else Consecutive_Zero+1;
if last.Return;
if Return= 0;
Incident_No+1;

run;
2 REPLIES 2
mkeintz
PROC Star

Please provide, in the form of a sas DATA step, a sample of your data.   And an example of what you expect the output to look like.  Your question has too many ambiguities for me to feel I understand it properly.

 

Help us help you.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Patrick
Opal | Level 21

Same logic just not using sub-setting IF. Does this make it better understandable for you?

/** 
calculating number of incidents of zero returns everyday
and number of zero returns in each of those incidents 
**/
data Zero_Returns;
  set HUF;
  by Date Return notsorted;
  if first.Date then Incident_No= 0;
  if first.Return then Consecutive_Zero= 1;
  else Consecutive_Zero+1;
  if last.Return and Return= 0 then
    do;
      Incident_No+1;
      output;
    end;
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
  • 2 replies
  • 363 views
  • 0 likes
  • 3 in conversation