<?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: Creating a universal macro to derive EPOCH in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-universal-macro-to-derive-EPOCH/m-p/716177#M221292</link>
    <description>&lt;P&gt;Are you trying to create a new variable in the dataset? Or change the value of a variable that already exists? What if the original dataset has both of those variables? Which value do you want to use?&lt;/P&gt;
&lt;P&gt;Your %IF statement conditions can never be true.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;dsn.dtc ne '' %then %do; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;No matter what value the macro variable DSN have you are comparing one string of letters that always include the letters dtc to the a pair of single quote characters.&amp;nbsp; Those can never be true.&lt;/P&gt;
&lt;P&gt;If you just want to populate DATE with which ever or AEDTC or AESTDTC is populated just use the COALESCEC() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;_DATE = coalescec(&amp;amp;dsn.DTC,&amp;amp;dsn.STDTC);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to force both AEDTC and AESTDTC to exist without knowing whether or not either exists or not one trick might be to add a FORMAT statement after the MERGE statement.&amp;nbsp; This will not modify the variable if it already exists, but it will let SAS guess to make a new variable with the right type and length if one does not already exist.&amp;nbsp; Not an ideal solution but a lot easier than querying the SAS metadata to find out if the variable exists or not.&lt;/P&gt;</description>
    <pubDate>Tue, 02 Feb 2021 19:00:44 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-02-02T19:00:44Z</dc:date>
    <item>
      <title>Creating a universal macro to derive EPOCH</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-universal-macro-to-derive-EPOCH/m-p/716165#M221288</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm having some issues trying to write the syntax for this macro. Basically, what I want it to do is to calculate _date variable if one or the other variable exists. For example, certain datasets have the --DTC variable and certain datasets have --STDTC variable. I want the code to calculate _date if the dataset has --DTC variable, but if the dataset doesn't have the --DTC variable then the _date variable is calculated using --STDTC variable. Currently, it's failing because of the first condition where I have set &amp;amp;dsn.dtc is causing _date to not be calculated because the dataset I have does not have DTC but instead has --STDTC.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro util_generate_epoch(dsn= );&lt;BR /&gt;data ec;&lt;BR /&gt;set c373_un.ec(keep=usubjid ecstdtc);&lt;BR /&gt;ECSTD=substr(ecstdtc,1,10);&lt;BR /&gt;_ECSTD=input(ecstd,yymmdd10.);&lt;BR /&gt;format _ecstd yymmdd10.;&lt;BR /&gt;drop ecstdtc ECSTD;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data=ec;&lt;BR /&gt;by usubjid;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data=&amp;amp;dsn.;&lt;BR /&gt;by usubjid;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data test;&lt;BR /&gt;length EPOCH $30;&lt;BR /&gt;merge &amp;amp;dsn.(in=a) ec(in=b);&lt;BR /&gt;by usubjid;&lt;BR /&gt;if a;&lt;BR /&gt;%if &amp;amp;dsn.dtc ne '' %then %do;&amp;nbsp;&lt;BR /&gt;_date=substr(&amp;amp;dsn.DTC,1,10);&lt;BR /&gt;%end;&lt;BR /&gt;%else %if &amp;amp;dsn.stdtc ne '' %then %do;&lt;BR /&gt;_date=substr(&amp;amp;dsn.stdtc,1,10);&lt;BR /&gt;%end;&lt;BR /&gt;_date2=input(_date,yymmdd10.);&lt;BR /&gt;format _date2 yymmdd10.;&lt;BR /&gt;_days=_ecstd-_date2 +1;&lt;BR /&gt;if -42 &amp;lt;= _days &amp;lt; -21 then EPOCH="SCREENING";&lt;BR /&gt;else if -21 &amp;lt;= _days &amp;lt;=0 then EPOCH="BASELINE";&lt;BR /&gt;else if 0 &amp;lt; _days &amp;lt;= 730 then EPOCH="SHORT TERM FOLLOW-UP";&lt;BR /&gt;else if 730 &amp;lt; _days &amp;lt;= 2190 then EPOCH="LONG TERM FOLLOW-UP";&lt;BR /&gt;*drop _days _ecstd _date _date2;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%mend;&lt;BR /&gt;%util_generate_epoch(dsn=ae);&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 18:22:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-universal-macro-to-derive-EPOCH/m-p/716165#M221288</guid>
      <dc:creator>Dregerator</dc:creator>
      <dc:date>2021-02-02T18:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a universal macro to derive EPOCH</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-universal-macro-to-derive-EPOCH/m-p/716171#M221291</link>
      <description>&lt;P&gt;Just what do these variables look like?&lt;/P&gt;
&lt;P&gt;Any time I see "date" mentioned with string functions I cringe because if often means someone is doing something bordering on unnatural.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 18:46:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-universal-macro-to-derive-EPOCH/m-p/716171#M221291</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-02T18:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a universal macro to derive EPOCH</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-universal-macro-to-derive-EPOCH/m-p/716177#M221292</link>
      <description>&lt;P&gt;Are you trying to create a new variable in the dataset? Or change the value of a variable that already exists? What if the original dataset has both of those variables? Which value do you want to use?&lt;/P&gt;
&lt;P&gt;Your %IF statement conditions can never be true.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;dsn.dtc ne '' %then %do; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;No matter what value the macro variable DSN have you are comparing one string of letters that always include the letters dtc to the a pair of single quote characters.&amp;nbsp; Those can never be true.&lt;/P&gt;
&lt;P&gt;If you just want to populate DATE with which ever or AEDTC or AESTDTC is populated just use the COALESCEC() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;_DATE = coalescec(&amp;amp;dsn.DTC,&amp;amp;dsn.STDTC);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to force both AEDTC and AESTDTC to exist without knowing whether or not either exists or not one trick might be to add a FORMAT statement after the MERGE statement.&amp;nbsp; This will not modify the variable if it already exists, but it will let SAS guess to make a new variable with the right type and length if one does not already exist.&amp;nbsp; Not an ideal solution but a lot easier than querying the SAS metadata to find out if the variable exists or not.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 19:00:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-universal-macro-to-derive-EPOCH/m-p/716177#M221292</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-02T19:00:44Z</dc:date>
    </item>
  </channel>
</rss>

