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

Hi TEam,

I was reading a paper on Dow Loops.

http://analytics.ncsu.edu/sesug/2010/BB13.Dorfman.pdf

The example is from page 2 of this paper.

"If VAR is missing CONTINUE passes the control straight to the bottom of the loop".

What is the meaning of bottom of the loop? Is it not gona calculate Mcount Prod and SUm for that variable and goes to the next variable but still with in the loop?Is that the meaning ?

Secondly,

"PROD and COUNT are

set to 1, and the non-retained SUM, MEAN, and MCOUNT are set to missing by the default action of the

implied loop (program control at the top of the implied loop)."

This sentence says that SUM Mean and Count are set to missing . But what lines in the code sets these values to missing??

Any help is greatly appreciated possibly with an example would be great

Thanks

Data B ( Keep = Id Prod Sum Count Mean) ;

  Prod = 1 ;

   Do Count = 1 By 1 Until ( Last.Id ) ;

   Set A ;

    By Id ;

       If Missing (Var) Then Continue ;

      Mcount = Sum (Mcount, 1) ;

       Prod = Prod * Var ;

       Sum = Sum (Sum, Var) ;

       End ;

       Mean = Sum / Mcount ;

Run ;

Message was edited by: Karun Diri Also I feel the keep statement would have been good with the set statement rather than the Data B Any suggestions??

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

MCOUNT = mean count = nonmissing values.

If I may offer some advice, I think you are struggling with the abstractions presented by macros and advanced SUGI papers that aren't necessary to master until you gain more experience.  I know people who have been SAS programmers for years and who have never written a DOW loop.  When I was first learning SAS, I liked to experiment with SAS on data that was small, concrete, and familiar.  I suggest you run and study this concrete example. And when the next question comes up, see if you can construct a simple example that uses the Sashelp.Class data set. It is the "best friend" of discussion forums because it enables everyone to run the example and to speak in terms of concrete variables and observations.

/* sort data to enable BY group analysis */
proc sort data=sashelp.class out=class;
by sex;
run;

title "Original data";
proc print data=Class; run;

/* compute mean as an example of a DOW loop */
Data B ( Keep = Sex MCountSum Mean) ;
   Do Until ( Last.Sex ) ;
   Set Class ;
   By Sex;
      If Missing (Age) Then Continue ;
      MCount = Sum (MCount, 1) ;
      Sum = Sum (Sum, Age) ;
      put _ALL_; /* look in the SAS LOG to see each iteration */
   End;
   Mean = Sum / MCount;
Run ;

title "Computed results";
proc print data=B; run;

/* compare result to standard call to PROC MEANS */
title "Results of PROC MEANS";
proc means data=class Sum Mean;
class sex;
var age;
run;

View solution in original post

5 REPLIES 5
Rick_SAS
SAS Super FREQ

Karun,

I'm glad you are learning about SAS. Did you know that there is a SAS Community forum dedicated to the DATA step, macros, and other questions that you've been asking? https://communities.sas.com/community/support-communities/sas_macro_facility_data_step_and_sas_langu...

I think that your questions are better suited for that forum because (1) there are more experts there, and (2) the readers of those forums can learn from your questions and from the posted answers.

The forum for Statistical Procedures is primarily intended for questions about procedures in SAS/STAT such as PROC REG, GLM, LOGISTIC, PRINCOMP, and so forth.

Best wishes for successful learning,

Rick

robertrao
Quartz | Level 8

Thanks Rick,

I didnt know about that. Infact i was confused. When you first directed me to use SAS almost 3 months ago u posted a link and I was blindly following to post questions on that forum...I will explore a little bit..

Thanks for the help

Rick_SAS
SAS Super FREQ

Yeah, I kind of figured that. I should have sent you to the main page. Bookmark this URL and then pick the sub-forum that fits the question you want to ask: https://communities.sas.com/community/support-communities

BTW: You can't use the KEEP statement on the SET statement because those variables (except ID) don't live in the A data set. They are being manufactured in the current DATA step from the Var variable (which does live in A).

robertrao
Quartz | Level 8

Got you.

1)I am confused with what  MCOUNT does?does  it stand for missing count??

2)if mising (var) then continue

he says that continue passes control to the bottom of the loop.

Bottom means he is not wanting to calculate the MCOUNT PROD AND SUM if a variable has missing value? Is that true???

Thanks

Rick_SAS
SAS Super FREQ

MCOUNT = mean count = nonmissing values.

If I may offer some advice, I think you are struggling with the abstractions presented by macros and advanced SUGI papers that aren't necessary to master until you gain more experience.  I know people who have been SAS programmers for years and who have never written a DOW loop.  When I was first learning SAS, I liked to experiment with SAS on data that was small, concrete, and familiar.  I suggest you run and study this concrete example. And when the next question comes up, see if you can construct a simple example that uses the Sashelp.Class data set. It is the "best friend" of discussion forums because it enables everyone to run the example and to speak in terms of concrete variables and observations.

/* sort data to enable BY group analysis */
proc sort data=sashelp.class out=class;
by sex;
run;

title "Original data";
proc print data=Class; run;

/* compute mean as an example of a DOW loop */
Data B ( Keep = Sex MCountSum Mean) ;
   Do Until ( Last.Sex ) ;
   Set Class ;
   By Sex;
      If Missing (Age) Then Continue ;
      MCount = Sum (MCount, 1) ;
      Sum = Sum (Sum, Age) ;
      put _ALL_; /* look in the SAS LOG to see each iteration */
   End;
   Mean = Sum / MCount;
Run ;

title "Computed results";
proc print data=B; run;

/* compare result to standard call to PROC MEANS */
title "Results of PROC MEANS";
proc means data=class Sum Mean;
class sex;
var age;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1994 views
  • 4 likes
  • 2 in conversation