Learning SAS? Welcome to the exclusive online community for all SAS learners.

Are SAS statements DO WHILE and DO UNTIL perfect substitutes in any case? Explain when they are substitutes, and when (if) they are not, and why.

Reply
Occasional Contributor
Posts: 12

Are SAS statements DO WHILE and DO UNTIL perfect substitutes in any case? Explain when they are substitutes, and when (if) they are not, and why.

Hello all, this is my 3rd/4 questions!

I am trying to understand the named question above. I am posting it below for convenience:

Are SAS statements DO WHILE and DO UNTIL perfect substitutes in any case? Explain when they are substitutes, and when (if) they are not, and why.

I am expected to format my answers by including the following:



a) find out, for each issue, between 3 and 5 interesting documentation sources (eg SAS User's manuals, SAS course notes, archives of the SAS-L list, forums like SAS communities, SUGI papers, blogs on SAS, courses offered on university sites,...) explaining how to deal efficiently with this issue

b) for each issue, give all the possible answers, explaining their relative characteristics and advantages, indicating the sources where the information was found.

c) for each issue, the final synthesis should be very clear, proofread and potentially useful for people looking for explanations about the way to deal with the data management issues at stake, using SAS. It implies that, for each issue, the assignment should start with a brief explanation of what the issue is, then explain how to deal with this issue, and end with at least two short examples (easy to understand and to replicate) with comments between /* */.

I appreciate comprehensive help, as these answers will enable better understanding and better performance on my upcoming exam.

Kind regards!

Super User
Posts: 19,772

Re: Are SAS statements DO WHILE and DO UNTIL perfect substitutes in any case? Explain when they are substitutes, and when (if) they are not, and why.

Posted in reply to rbs_LISER
Occasional Contributor
Posts: 12

Re: Are SAS statements DO WHILE and DO UNTIL perfect substitutes in any case? Explain when they are substitutes, and when (if) they are not, and why.

Hello Reeze, Thank you for addressing the question. Do you have any feedback for the "why" part of the question?

Respected Advisor
Posts: 3,799

Re: Are SAS statements DO WHILE and DO UNTIL perfect substitutes in any case? Explain when they are substitutes, and when (if) they are not, and why.

Posted in reply to rbs_LISER

Here an acceptable example that shows a different between using UNTIL/WHILE to read a SAS data set.

Do you see the difference and can you explain it?

data _null_;
  
put 'Top ' _n_= eof=;
   do until(eof);
      set sashelp.class(where=(age=20)) end=eof;
      end;
  
put 'After do, did we make it?';
  
stop;
  
run;

data _null_;
  
put 'Top ' _n_= eof=;
   do while(not eof);
      set sashelp.class(where=(age=20)) end=eof;
      end;
  
put 'After do, did we make it?';
  
stop;
  
run;



23         data _null_;
24            put 'Top ' _n_= eof=;
25            do until(eof);
26               set sashelp.class(where=(age=20)) end=eof;
27               end;
28            put 'After do, did we make it?';
29            stop;
30            run;

Top _N_=1 eof=1
NOTE: There were
0 observations read from the data set SASHELP.CLASS.
      WHERE age=
20;
31        
32         data _null_;
33            put 'Top ' _n_= eof=;
34            do while(not eof);
35               set sashelp.class(where=(age=20)) end=eof;
36               end;
37            put 'After do, did we make it?';
38            stop;
39            run;

Top _N_=1 eof=1
After do, did we make it?
NOTE: There were
0 observations read from the data set SASHELP.CLASS.
      WHERE age=
20;
Respected Advisor
Posts: 4,920

Re: Are SAS statements DO WHILE and DO UNTIL perfect substitutes in any case? Explain when they are substitutes, and when (if) they are not, and why.

Posted in reply to data_null__

Hint to explain example: Explain why the stop statement is optional with the until() loop but required with the while() loop. - PG

PG
Occasional Contributor
Posts: 12

Re: Are SAS statements DO WHILE and DO UNTIL perfect substitutes in any case? Explain when they are substitutes, and when (if) they are not, and why.

Thank you very much PG.

Occasional Contributor
Posts: 12

Re: Are SAS statements DO WHILE and DO UNTIL perfect substitutes in any case? Explain when they are substitutes, and when (if) they are not, and why.

Posted in reply to data_null__

Well, the stop statement is optional with the until but required with the while loop. Reason being is that the until loop statement is evaluated at the bottom of the loop, and the while statement is evaluated at the top. Yet, I still don't understand substantively what is going on.

SAS Super FREQ
Posts: 3,752

Re: Are SAS statements DO WHILE and DO UNTIL perfect substitutes in any case? Explain when they are substitutes, and when (if) they are not, and why.

Posted in reply to rbs_LISER

This article compares DO WHILE and DO UNTIL: http://blogs.sas.com/content/iml/2011/09/07/loops-in-sas.html

Ask a Question
Discussion stats
  • 7 replies
  • 492 views
  • 3 likes
  • 5 in conversation