<?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: want to write to global dataset from a macro(but it is erasing previous writes) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/want-to-write-to-global-dataset-from-a-macro-but-it-is-erasing/m-p/115331#M23746</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;try adding another macro variable:&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;%macro LMGenerate(mymktdata,yeartag,dsn);&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;data &amp;amp;mymktdata.highliquidity;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;*blah blah;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;data &amp;amp;mymktdata.lowliquidity;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;*blah blah;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;*this is basically difference of above 2 datasets&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;data &amp;amp;dsn._ liquiditypremiums;&lt;BR /&gt;&amp;nbsp; update &amp;amp;mymktdata.lowliquidity(in = a)&amp;nbsp; &amp;amp;mymktdata.highliquidity(in =b);&lt;BR /&gt;&amp;nbsp; by year;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;&amp;nbsp; if a &amp;amp; b then&lt;BR /&gt;&amp;nbsp; do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; netpremium=lowliquiditytotal-highliquiditytotal;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;%mend&amp;nbsp; LMGenerate;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;&amp;nbsp; &lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;%LMGenerate(yr2010mktdata,2010,aaa )&lt;BR /&gt;%LMGenerate(yr2011mktdata,2011,bbb )&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 20 Feb 2013 02:24:41 GMT</pubDate>
    <dc:creator>Linlin</dc:creator>
    <dc:date>2013-02-20T02:24:41Z</dc:date>
    <item>
      <title>want to write to global dataset from a macro(but it is erasing previous writes)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/want-to-write-to-global-dataset-from-a-macro-but-it-is-erasing/m-p/115330#M23745</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;I have a macro which processes a dataset. I want to preserve the final outcome of this processing. So I am writing the final outcome to a global dataset(I could not think of any other alternative in SAS to make macro preserve the final outcome). This works good if I call macro once. However when I call macro more than once, only the last write is preserved(apparently previous writes are erased and I am preserved with only 1 final outcome in global dataset).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;Assuming writing to global dataset is preferred way to preserve the final outcome of a macro, how can I RETAIN the writes to global dataset (instead of overwriting the previous content and preserving only 1 write in global dataset). Here is SAS snippet I am using..thank you&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro LMGenerate(mymktdata,yeartag);&lt;/P&gt;&lt;P&gt; data &amp;amp;mymktdata.highliquidity;&lt;/P&gt;&lt;P&gt; *blah blah;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; data &amp;amp;mymktdata.lowliquidity;&lt;/P&gt;&lt;P&gt; *blah blah;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*this is basically difference of above 2 datasets&lt;/P&gt;&lt;P&gt;data&amp;nbsp; liquiditypremiums;&lt;BR /&gt;&amp;nbsp; update &amp;amp;mymktdata.lowliquidity(in = a)&amp;nbsp; &amp;amp;mymktdata.highliquidity(in =b);&lt;BR /&gt;&amp;nbsp; by year;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if a &amp;amp; b then&lt;BR /&gt;&amp;nbsp; do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; netpremium=lowliquiditytotal-highliquiditytotal;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend&amp;nbsp; LMGenerate;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*global data;&lt;/P&gt;&lt;P&gt;data liquiditypremiums;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%LMGenerate(yr2010mktdata,2010 )&lt;BR /&gt;%LMGenerate(yr2011mktdata,2011 )&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Feb 2013 01:57:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/want-to-write-to-global-dataset-from-a-macro-but-it-is-erasing/m-p/115330#M23745</guid>
      <dc:creator>kashili</dc:creator>
      <dc:date>2013-02-20T01:57:02Z</dc:date>
    </item>
    <item>
      <title>Re: want to write to global dataset from a macro(but it is erasing previous writes)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/want-to-write-to-global-dataset-from-a-macro-but-it-is-erasing/m-p/115331#M23746</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;try adding another macro variable:&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;%macro LMGenerate(mymktdata,yeartag,dsn);&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;data &amp;amp;mymktdata.highliquidity;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;*blah blah;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;data &amp;amp;mymktdata.lowliquidity;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;*blah blah;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;*this is basically difference of above 2 datasets&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;data &amp;amp;dsn._ liquiditypremiums;&lt;BR /&gt;&amp;nbsp; update &amp;amp;mymktdata.lowliquidity(in = a)&amp;nbsp; &amp;amp;mymktdata.highliquidity(in =b);&lt;BR /&gt;&amp;nbsp; by year;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;&amp;nbsp; if a &amp;amp; b then&lt;BR /&gt;&amp;nbsp; do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; netpremium=lowliquiditytotal-highliquiditytotal;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;%mend&amp;nbsp; LMGenerate;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;&amp;nbsp; &lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;%LMGenerate(yr2010mktdata,2010,aaa )&lt;BR /&gt;%LMGenerate(yr2011mktdata,2011,bbb )&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Feb 2013 02:24:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/want-to-write-to-global-dataset-from-a-macro-but-it-is-erasing/m-p/115331#M23746</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2013-02-20T02:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: want to write to global dataset from a macro(but it is erasing previous writes)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/want-to-write-to-global-dataset-from-a-macro-but-it-is-erasing/m-p/115332#M23747</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure what you mean by a "global" dataset.&amp;nbsp; You only seem to be creating WORK datasets.&lt;/P&gt;&lt;P&gt;If you want to append results to a dataset you might want to look at PROC APPEND.&lt;/P&gt;&lt;P&gt;Here is a trivial example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro xx(value);&lt;/P&gt;&lt;P&gt;* Calculate new values ;&lt;/P&gt;&lt;P&gt;data new;&lt;/P&gt;&lt;P&gt;&amp;nbsp; x=&amp;amp;value;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc append base=global data=new force;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend xx;&lt;/P&gt;&lt;P&gt;%xx(1);&lt;/P&gt;&lt;P&gt;%xx(2);&lt;/P&gt;&lt;P&gt;proc print data=global;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Feb 2013 03:53:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/want-to-write-to-global-dataset-from-a-macro-but-it-is-erasing/m-p/115332#M23747</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-02-20T03:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: want to write to global dataset from a macro(but it is erasing previous writes)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/want-to-write-to-global-dataset-from-a-macro-but-it-is-erasing/m-p/115333#M23748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By default, SAS will replace the dataset if you supply the same name in your DATA statement that you named in your UPDATE, SET or MERGE statement...So here when you call the macro more than once, the you lose the prior update and finally you only have one dataset which overwrite the prior datasets...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think in this case, use &lt;STRONG&gt;GENMAX&amp;nbsp; = n&lt;/STRONG&gt; option in data step...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro LMGenerate(mymktdata,yeartag);&lt;/P&gt;&lt;P&gt;data &amp;amp;mymktdata.highliquidity;&lt;/P&gt;&lt;P&gt;*blah blah;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data &amp;amp;mymktdata.lowliquidity;&lt;/P&gt;&lt;P&gt;*blah blah;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*this is basically difference of above 2 datasets&lt;/P&gt;&lt;P&gt;data&amp;nbsp; liquiditypremiums &lt;STRONG&gt;(genmax = 3);&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp; update &amp;amp;mymktdata.lowliquidity(in = a)&amp;nbsp; &amp;amp;mymktdata.highliquidity(in =b);&lt;BR /&gt;&amp;nbsp; by year;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if a &amp;amp; b then&lt;BR /&gt;&amp;nbsp; do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; netpremium=lowliquiditytotal-highliquiditytotal;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend&amp;nbsp; LMGenerate;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*global data;&lt;/P&gt;&lt;P&gt;data liquiditypremiums;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%LMGenerate(yr2010mktdata,2010 )&lt;BR /&gt;%LMGenerate(yr2011mktdata,2011 )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Urvish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Feb 2013 04:29:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/want-to-write-to-global-dataset-from-a-macro-but-it-is-erasing/m-p/115333#M23748</guid>
      <dc:creator>UrvishShah</dc:creator>
      <dc:date>2013-02-20T04:29:52Z</dc:date>
    </item>
    <item>
      <title>Re: want to write to global dataset from a macro(but it is erasing previous writes)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/want-to-write-to-global-dataset-from-a-macro-but-it-is-erasing/m-p/115334#M23749</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Linlin&lt;/P&gt;&lt;P&gt;what is 'aaa' and 'bbb'? Not sure how to fit in macro variable here (I am newbie..).&lt;/P&gt;&lt;P&gt;I have a&amp;nbsp; dataset outside macro and I need my macro to append some values to this&amp;nbsp; dataset (so that I can do post processing after all macros are executed).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Feb 2013 16:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/want-to-write-to-global-dataset-from-a-macro-but-it-is-erasing/m-p/115334#M23749</guid>
      <dc:creator>kashili</dc:creator>
      <dc:date>2013-02-20T16:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: want to write to global dataset from a macro(but it is erasing previous writes)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/want-to-write-to-global-dataset-from-a-macro-but-it-is-erasing/m-p/115335#M23750</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;try the code below to see if you get what you want (repace the &lt;SPAN style="color: #ff0000;"&gt;RED&lt;/SPAN&gt; part with your real dataset name, the dataset you want to add obsevations on):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro LMGenerate(mymktdata,yeartag);&lt;BR /&gt; data &amp;amp;mymktdata.highliquidity;&lt;BR /&gt; *blah blah;&lt;BR /&gt;run;&lt;BR /&gt; &lt;BR /&gt; data &amp;amp;mymktdata.lowliquidity;&lt;BR /&gt; *blah blah;&lt;BR /&gt;run;&lt;BR /&gt; &lt;BR /&gt;*this is basically difference of above 2 datasets&lt;BR /&gt;data&amp;nbsp; _&amp;amp;mymktdata;&lt;BR /&gt;&amp;nbsp; update &amp;amp;mymktdata.lowliquidity(in = a)&amp;nbsp; &amp;amp;mymktdata.highliquidity(in =b);&lt;BR /&gt;&amp;nbsp; by year;&lt;BR /&gt;&amp;nbsp; if a &amp;amp; b then&lt;BR /&gt;&amp;nbsp; do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; netpremium=lowliquiditytotal-highliquiditytotal;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt; run;&lt;BR /&gt; &lt;BR /&gt;%mend&amp;nbsp; LMGenerate;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%LMGenerate(yr2010mktdata,2010 )&lt;BR /&gt;%LMGenerate(yr2011mktdata,2011 )&lt;BR /&gt;*global data;&lt;BR /&gt;data want;&lt;BR /&gt;&amp;nbsp; set &lt;SPAN style="color: #ff0000;"&gt;your_global_dataset_name &lt;/SPAN&gt; _:;&lt;BR /&gt; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Feb 2013 18:35:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/want-to-write-to-global-dataset-from-a-macro-but-it-is-erasing/m-p/115335#M23750</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2013-02-20T18:35:23Z</dc:date>
    </item>
  </channel>
</rss>

