<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic 2 where statements in a Data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/2-where-statements-in-a-Data-step/m-p/684080#M207270</link>
    <description>&lt;PRE&gt;Hello everyone,&lt;BR /&gt;&lt;BR /&gt;I have some questions about the following code and its answer choice. This is a problem of sas practice for base exam.&lt;BR /&gt;The right answer is A.&lt;BR /&gt;&lt;BR /&gt;(1) In the user-defined format, the right side of "=" is some date formats, which are put inside&lt;BR /&gt;of []. Is this true for all the cases of any format on the right? &lt;BR /&gt;&lt;BR /&gt;(2) I thought this program subsets all the observations by year 1980 and later, not 1991.&lt;BR /&gt;The second where statement overwrites the first one. Any comments? Thanks.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;title;
proc format;
   value yrgroup low - '31dec1991'd = [year.]
                 '01jan1992'd - high = [monyy.]
;
run;

proc print data=SASHelp.retail noobs; 
   where date &amp;gt; '01Jan1991'd;  
   var date sales;
   format date yrgroup.;
   where date &amp;gt; '01Jan1980'd; 
run;&lt;/PRE&gt;
&lt;DIV class="qtext"&gt;Which statement describes the results?&lt;BR /&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="ablock"&gt;
&lt;DIV class="prompt"&gt;Select one:&lt;/DIV&gt;
&lt;DIV class="answer"&gt;
&lt;DIV class="r0 correct"&gt;&lt;INPUT id="q232693:54_answer0" checked="checked" disabled="disabled" name="q232693:54_answer" type="radio" value="0" /&gt;&lt;LABEL class="d-flex w-100" for="q232693:54_answer0"&gt;&lt;LABEL class="d-flex w-100" for="q232693:54_answer0"&gt;&lt;SPAN class="answernumber"&gt;A.&lt;/SPAN&gt;&lt;/LABEL&gt;&lt;/LABEL&gt;
&lt;DIV class="flex-fill ml-1"&gt;The report generated by the PRINT procedure will summarize sales by year through 1991 and after by month and year.&lt;/DIV&gt;
&lt;I class="icon fa fa-check text-success fa-fw " aria-label="Correct"&gt;&lt;/I&gt;&lt;/DIV&gt;
&lt;DIV class="r1"&gt;&lt;INPUT id="q232693:54_answer1" disabled="disabled" name="q232693:54_answer" type="radio" value="1" /&gt;&lt;LABEL class="d-flex w-100" for="q232693:54_answer1"&gt;&lt;LABEL class="d-flex w-100" for="q232693:54_answer1"&gt;&lt;SPAN class="answernumber"&gt;B.&lt;/SPAN&gt;&lt;/LABEL&gt;&lt;/LABEL&gt;
&lt;DIV class="flex-fill ml-1"&gt;The FORMAT procedure will fail but the PRINT procedure will summarize by date disregarding the FORMAT statement.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="r0"&gt;&lt;INPUT id="q232693:54_answer2" disabled="disabled" name="q232693:54_answer" type="radio" value="2" /&gt;&lt;LABEL class="d-flex w-100" for="q232693:54_answer2"&gt;&lt;LABEL class="d-flex w-100" for="q232693:54_answer2"&gt;&lt;SPAN class="answernumber"&gt;C.&lt;/SPAN&gt;&lt;/LABEL&gt;&lt;/LABEL&gt;
&lt;DIV class="flex-fill ml-1"&gt;The FORMAT procedure will fail to create a format and thus the PRINT procedure will fail as the format cannot be found.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="r1"&gt;&lt;INPUT id="q232693:54_answer3" disabled="disabled" name="q232693:54_answer" type="radio" value="3" /&gt;&lt;LABEL class="d-flex w-100" for="q232693:54_answer3"&gt;&lt;LABEL class="d-flex w-100" for="q232693:54_answer3"&gt;&lt;SPAN class="answernumber"&gt;D.&lt;/SPAN&gt;&lt;/LABEL&gt;&lt;/LABEL&gt;
&lt;DIV class="flex-fill ml-1"&gt;The PRINT procedure will fail as there are conflicting WHERE statements.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Wed, 16 Sep 2020 00:33:19 GMT</pubDate>
    <dc:creator>jkl123</dc:creator>
    <dc:date>2020-09-16T00:33:19Z</dc:date>
    <item>
      <title>2 where statements in a Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2-where-statements-in-a-Data-step/m-p/684080#M207270</link>
      <description>&lt;PRE&gt;Hello everyone,&lt;BR /&gt;&lt;BR /&gt;I have some questions about the following code and its answer choice. This is a problem of sas practice for base exam.&lt;BR /&gt;The right answer is A.&lt;BR /&gt;&lt;BR /&gt;(1) In the user-defined format, the right side of "=" is some date formats, which are put inside&lt;BR /&gt;of []. Is this true for all the cases of any format on the right? &lt;BR /&gt;&lt;BR /&gt;(2) I thought this program subsets all the observations by year 1980 and later, not 1991.&lt;BR /&gt;The second where statement overwrites the first one. Any comments? Thanks.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;title;
proc format;
   value yrgroup low - '31dec1991'd = [year.]
                 '01jan1992'd - high = [monyy.]
;
run;

proc print data=SASHelp.retail noobs; 
   where date &amp;gt; '01Jan1991'd;  
   var date sales;
   format date yrgroup.;
   where date &amp;gt; '01Jan1980'd; 
run;&lt;/PRE&gt;
&lt;DIV class="qtext"&gt;Which statement describes the results?&lt;BR /&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="ablock"&gt;
&lt;DIV class="prompt"&gt;Select one:&lt;/DIV&gt;
&lt;DIV class="answer"&gt;
&lt;DIV class="r0 correct"&gt;&lt;INPUT id="q232693:54_answer0" checked="checked" disabled="disabled" name="q232693:54_answer" type="radio" value="0" /&gt;&lt;LABEL class="d-flex w-100" for="q232693:54_answer0"&gt;&lt;LABEL class="d-flex w-100" for="q232693:54_answer0"&gt;&lt;SPAN class="answernumber"&gt;A.&lt;/SPAN&gt;&lt;/LABEL&gt;&lt;/LABEL&gt;
&lt;DIV class="flex-fill ml-1"&gt;The report generated by the PRINT procedure will summarize sales by year through 1991 and after by month and year.&lt;/DIV&gt;
&lt;I class="icon fa fa-check text-success fa-fw " aria-label="Correct"&gt;&lt;/I&gt;&lt;/DIV&gt;
&lt;DIV class="r1"&gt;&lt;INPUT id="q232693:54_answer1" disabled="disabled" name="q232693:54_answer" type="radio" value="1" /&gt;&lt;LABEL class="d-flex w-100" for="q232693:54_answer1"&gt;&lt;LABEL class="d-flex w-100" for="q232693:54_answer1"&gt;&lt;SPAN class="answernumber"&gt;B.&lt;/SPAN&gt;&lt;/LABEL&gt;&lt;/LABEL&gt;
&lt;DIV class="flex-fill ml-1"&gt;The FORMAT procedure will fail but the PRINT procedure will summarize by date disregarding the FORMAT statement.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="r0"&gt;&lt;INPUT id="q232693:54_answer2" disabled="disabled" name="q232693:54_answer" type="radio" value="2" /&gt;&lt;LABEL class="d-flex w-100" for="q232693:54_answer2"&gt;&lt;LABEL class="d-flex w-100" for="q232693:54_answer2"&gt;&lt;SPAN class="answernumber"&gt;C.&lt;/SPAN&gt;&lt;/LABEL&gt;&lt;/LABEL&gt;
&lt;DIV class="flex-fill ml-1"&gt;The FORMAT procedure will fail to create a format and thus the PRINT procedure will fail as the format cannot be found.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="r1"&gt;&lt;INPUT id="q232693:54_answer3" disabled="disabled" name="q232693:54_answer" type="radio" value="3" /&gt;&lt;LABEL class="d-flex w-100" for="q232693:54_answer3"&gt;&lt;LABEL class="d-flex w-100" for="q232693:54_answer3"&gt;&lt;SPAN class="answernumber"&gt;D.&lt;/SPAN&gt;&lt;/LABEL&gt;&lt;/LABEL&gt;
&lt;DIV class="flex-fill ml-1"&gt;The PRINT procedure will fail as there are conflicting WHERE statements.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 16 Sep 2020 00:33:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2-where-statements-in-a-Data-step/m-p/684080#M207270</guid>
      <dc:creator>jkl123</dc:creator>
      <dc:date>2020-09-16T00:33:19Z</dc:date>
    </item>
    <item>
      <title>Re: 2 where statements in a Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2-where-statements-in-a-Data-step/m-p/684081#M207271</link>
      <description>&lt;P&gt;The answer key appears to be just plain wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If two WHERE clauses are specified, SAS takes the most recent one and replaces any earlier WHERE clauses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just ran your code and got this message in my log:&lt;/P&gt;
&lt;PRE&gt;36         proc print data=SASHelp.retail noobs;
37            where date &amp;gt; '01Jan1991'd;
38            var date sales;
39            format date yrgroup.;
40            where date &amp;gt; '01Jan1980'd;
NOTE: WHERE clause has been replaced.
41         run;&lt;/PRE&gt;
&lt;P&gt;In other words, your data will be subsetted by 01JAN1980&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;not&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;01JAN1991&lt;EM&gt;.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Results are below.&amp;nbsp; Correct me if I am wrong, but I believe that I see data from January 1980 onward.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Practice_Exam_WHERE_Clause_Results_2020-09-15_17-46-26.jpg" style="width: 92px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49389i6D43D53EC0508A0B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Practice_Exam_WHERE_Clause_Results_2020-09-15_17-46-26.jpg" alt="Practice_Exam_WHERE_Clause_Results_2020-09-15_17-46-26.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 00:48:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2-where-statements-in-a-Data-step/m-p/684081#M207271</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-16T00:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: 2 where statements in a Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2-where-statements-in-a-Data-step/m-p/684095#M207276</link>
      <description>Thank you so much, Jim. This is also what I got before. It's unusual to see&lt;BR /&gt;something wrong in the official practice. But anyway, it's a good idea to&lt;BR /&gt;run the program.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 16 Sep 2020 02:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2-where-statements-in-a-Data-step/m-p/684095#M207276</guid>
      <dc:creator>jkl123</dc:creator>
      <dc:date>2020-09-16T02:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: 2 where statements in a Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2-where-statements-in-a-Data-step/m-p/684115#M207281</link>
      <description>&lt;P&gt;Yes, when in doubt, run the code.&amp;nbsp; Actual code trumps all answer keys.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suppose this topic is now "solved," at least in the sense that we know what's going on.&amp;nbsp; Far better to know what's going on than to try to talk yourself into accepting the answer key's solution and thereby mis-learning SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 03:45:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2-where-statements-in-a-Data-step/m-p/684115#M207281</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-16T03:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: 2 where statements in a Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2-where-statements-in-a-Data-step/m-p/684117#M207282</link>
      <description>&lt;P&gt;The code as posted runs without errors. There are some NOTES produced by both steps.&lt;/P&gt;
&lt;PRE&gt;188   proc format;
189      value yrgroup low - '31dec1991'd = [year.]
NOTE: The YEAR (in)format was specified on the right-hand side of an equal sign, but without a length
      specification. PROC FORMAT will assume a default length of at least 40 for the format being
      generated. If this is an insufficient width, you can rerun PROC FORMAT with an explicit width for
      the YEAR (in)format, or provide a sufficient DEFAULT= option.
190                    '01jan1992'd - high = [monyy.]
NOTE: The MONYY (in)format was specified on the right-hand side of an equal sign, but without a length
      specification. PROC FORMAT will assume a default length of at least 40 for the format being
      generated. If this is an insufficient width, you can rerun PROC FORMAT with an explicit width for
      the MONYY (in)format, or provide a sufficient DEFAULT= option.
191   ;
NOTE: Format YRGROUP has been output.
192   run;

NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.09 seconds
      cpu time            0.03 seconds


193
194   proc print data=SASHelp.retail noobs;
195      where date &amp;gt; '01Jan1991'd;
196      var date sales;
197      format date yrgroup.;
198      where date &amp;gt; '01Jan1980'd;
NOTE: WHERE clause has been replaced.
199   run;

NOTE: There were 57 observations read from the data set SASHELP.RETAIL.
      WHERE date&amp;gt;'01JAN1980'D;
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.21 seconds
      cpu time            0.06 seconds
&lt;/PRE&gt;
&lt;P&gt;Let's look at each answer and see how it stacks up to reality.&amp;nbsp; Then perhaps we can pick a least bad answer.&lt;/P&gt;
&lt;P&gt;Let's do in reverse order since they claim you should pick A.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;D&amp;nbsp;The PRINT procedure will fail as there are conflicting WHERE statements.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;There is no such things as conflicting WHERE statements. The last one cancels the earlier ones. You can see that in the notes in the SAS log.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;C&amp;nbsp;The FORMAT procedure will fail to create a format and thus the PRINT procedure will fail as the format cannot be found.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The is no obvious error with the format step.&amp;nbsp; The only issue is that the nested format specifications do not have widths specified. But as you can see from the notes in the log that does not stop the format from being created.&amp;nbsp; And a data step will only fail if the format is not found if you have set the FMTERR option. They do not mention anything about that being set.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;B&amp;nbsp;The FORMAT procedure will fail but the PRINT procedure will summarize by date disregarding the FORMAT statement.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So this is like C but they say that PRINT will ignore the missing format.&amp;nbsp; So that part is right.&amp;nbsp; But the first part is wrong.&amp;nbsp; But the PROC PRINT step does not "summarize" by anything.&amp;nbsp; Perhaps if you included a SUM statement for one or more of the variables in the VAR statement it might show totals for that variable.&amp;nbsp; Or perhaps if you add the N option to the PROC PRINT statement it would show a count of the number of observations.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;A The report generated by the PRINT procedure will summarize sales by year through 1991 and after by month and year.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This one is a little closer to the truth.&amp;nbsp; The PROC PRINT output will DISPLAY the date values as just the YEAR for dates before 1992 and as 3 letter month and year for the later dates.&amp;nbsp; But again the PROC PRINT is not "summarizing" anything.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Part of the output. You can see that there appears to be four observations for each year. Based on the later values apparently each on is for a date that is in a different month of that year.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 180px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49406i7FAD79C7D130AEB1/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So A is the best answer as it is the only one that describes what the format does (or even attempts to describe it).&amp;nbsp; So if I had to pick one I would choose A.&amp;nbsp; Is this strictly a multiple choice test? Or are you allowed to explain why you picked a given answer?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you wanted to summarize by DATE then use another procedure.&amp;nbsp; Like PROC MEANS.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=sashelp.retail ;
   where date &amp;gt; '01Jan1990'd; 
   where also date &amp;lt; '01JAN1993'd;
   format date yrgroup.;
   class date;
   var sales;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;The MEANS Procedure

           Analysis Variable : SALES Retail sales in millions of $

            N
DATE      Obs    N           Mean        Std Dev        Minimum        Maximum
------------------------------------------------------------------------------
1990        3    3    709.3333333     37.6873100    674.0000000    749.0000000

1991        4    4    736.7500000     48.0303723    703.0000000    807.0000000

JAN1992     1    1    692.0000000              .    692.0000000    692.0000000

APR1992     1    1    797.0000000              .    797.0000000    797.0000000

JUL1992     1    1    826.0000000              .    826.0000000    826.0000000

OCT1992     1    1    889.0000000              .    889.0000000    889.0000000
------------------------------------------------------------------------------
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 04:21:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2-where-statements-in-a-Data-step/m-p/684117#M207282</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-09-16T04:21:14Z</dc:date>
    </item>
  </channel>
</rss>

