<?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 Re: output in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/output/m-p/836881#M330901</link>
    <description>&lt;PRE&gt;data exchange;
    set exchange;
    retain _from;
    by from to;
    if first.to then valid_to=.;
    else valid_to = _from-1;
output;
    _from=valid_from;
    where to ='HKD';
    format _from valid_to_date9.;
run;

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;with the output command I am a bit confused, am I still right to say, the data steps only run when to='HKD'? like how I would interpret this data step where there is no output command...&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 05 Oct 2022 07:32:29 GMT</pubDate>
    <dc:creator>HeatherNewton</dc:creator>
    <dc:date>2022-10-05T07:32:29Z</dc:date>
    <item>
      <title>output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output/m-p/836854#M330882</link>
      <description>&lt;PRE&gt;data exchange;
    set wdata.exchange_rate;
    output;
    if _n_=1 then do;
        from ="HKD";
        to="HKD"
        exch_rate=1;
        valid_from = '01jan1000'd;
        output;
    end;
run;&lt;/PRE&gt;
&lt;P&gt;can you let me know if my interpretation is correct...&lt;/P&gt;
&lt;P&gt;for each observation in wdata.exchange_rate, it get output to the dataset exchange by the first 'output' in the code,&lt;/P&gt;
&lt;P&gt;then we check if _n_=1, if it is true, we update variables&lt;/P&gt;
&lt;P&gt;from ="HKD", to="HKD", exch_rate=1, valide_from='01jan1000'd&lt;/P&gt;
&lt;P&gt;and output them to dataset exchange..&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2022 04:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output/m-p/836854#M330882</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-10-05T04:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output/m-p/836856#M330884</link>
      <description>&lt;P&gt;Yes. It adds an observation after the first observation with the hardcoded values.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2022 04:14:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output/m-p/836856#M330884</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-05T04:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output/m-p/836865#M330890</link>
      <description>&lt;P&gt;Not quite.&lt;/P&gt;
&lt;P&gt;The "date" of '01jan1000'd is an invalid date constant, will generate an error and no new output will result.&lt;/P&gt;
&lt;P&gt;You have to use a year greater than 1581 (and less than 20001) to get a valid date literal.&lt;/P&gt;
&lt;PRE&gt;317  data example;
318     x = '01jan1000'd;
            ------------
            77
ERROR: Invalid date/time/datetime constant '01jan1000'd.
ERROR 77-185: Invalid number conversion on '01jan1000'd.

319  run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.EXAMPLE may be incomplete.  When this step was stopped there were 0
         observations and 1 variables.
&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;data exchange;
    set wdata.exchange_rate;
    output;
    if _n_=1 then do;
        from ="HKD";
        to="HKD"
        exch_rate=1;
        valid_from = '01jan1000'd;
        output;
    end;
run;&lt;/PRE&gt;
&lt;P&gt;can you let me know if my interpretation is correct...&lt;/P&gt;
&lt;P&gt;for each observation in wdata.exchange_rate, it get output to the dataset exchange by the first 'output' in the code,&lt;/P&gt;
&lt;P&gt;then we check if _n_=1, if it is true, we update variables&lt;/P&gt;
&lt;P&gt;from ="HKD", to="HKD", exch_rate=1, valide_from='01jan1000'd&lt;/P&gt;
&lt;P&gt;and output them to dataset exchange..&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2022 05:22:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output/m-p/836865#M330890</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-10-05T05:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output/m-p/836879#M330899</link>
      <description>&lt;P&gt;oh sorry I made a typo, should be 1999 instead of 1000..&lt;/P&gt;
&lt;P&gt;does it work if&lt;/P&gt;
&lt;P&gt;valid_from='01jan1999'd;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in the above??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;one more question what is the difference between&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'01jan1999'd&lt;/P&gt;
&lt;P&gt;and '01jan1999'd.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2022 06:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output/m-p/836879#M330899</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-10-05T06:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output/m-p/836880#M330900</link>
      <description>&lt;P&gt;'01jan1999'd is a valid SAS date literal.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;wrote:
&lt;P&gt;one more question what is the difference between&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'01jan1999'd&lt;/P&gt;
&lt;P&gt;and '01jan1999'd.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There is no difference.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2022 06:44:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output/m-p/836880#M330900</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-05T06:44:27Z</dc:date>
    </item>
    <item>
      <title>Re: output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output/m-p/836881#M330901</link>
      <description>&lt;PRE&gt;data exchange;
    set exchange;
    retain _from;
    by from to;
    if first.to then valid_to=.;
    else valid_to = _from-1;
output;
    _from=valid_from;
    where to ='HKD';
    format _from valid_to_date9.;
run;

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;with the output command I am a bit confused, am I still right to say, the data steps only run when to='HKD'? like how I would interpret this data step where there is no output command...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2022 07:32:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output/m-p/836881#M330901</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-10-05T07:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output/m-p/836886#M330905</link>
      <description>&lt;P&gt;As good coding practice, &amp;nbsp;a WHERE should always follow the SET/MERGE/UPDATE. Hiding it somewhere later in the code is confusing and BAD PRACTICE.&lt;/P&gt;
&lt;P&gt;WHERE is a declarative statement, so, for the data step compiler, its position in the code is irrelevant.&lt;/P&gt;
&lt;P&gt;This is the way I would write the code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data exchange;
set exchange (where=(to ='HKD'));
by from;
retain _from;
if first.from
then valid_to = .;
else valid_to = _from - 1;
output;
_from = valid_from;
format _from valid_to date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now the WHERE= is completely clear.&lt;/P&gt;
&lt;P&gt;Since the WHERE restricts variable "to" to only one value, its use in the BY is redundant. Therefore I reduce the BY and use a different FIRST. variable.&lt;/P&gt;
&lt;P&gt;Without seeing the data, I am not quite sure why the code does not reset _from at the FIRST. point. The way the code is written, the value in _from carries over from the last observation of the previous group to the first observation of the current group. Maybe _from is not really needed in the output and should be DROPped.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2022 08:19:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output/m-p/836886#M330905</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-05T08:19:00Z</dc:date>
    </item>
  </channel>
</rss>

