<?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 Extracting elements from a macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extracting-elements-from-a-macro-variable/m-p/766194#M242798</link>
    <description>&lt;P&gt;The sql procedure below (within a macro) generates a macro variable 'imp_date'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%macro imp_test;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;/* List of runs as macro variable */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;proc sql noprint; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;select cats(year(date),put(month(date),z2.)) into :imp_date separated by ' ' &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;from grid&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;where flag_qtr = 1 and date &amp;gt;= "&amp;amp;gen_date_first."d and date &amp;lt;= "&amp;amp;gen_date_last."d; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;quit;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;[...]&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%mend&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;,where&amp;nbsp;gen_date_first=31MAR2018,&amp;nbsp;gen_date_last=31DEC2020.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output:&lt;/P&gt;&lt;P&gt;IMP_DATE = 201803 201806 201809 201812 201903 201906 201909 201912 202003 202006 202009 202012&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I need to remove '202003' from imp_date, and tried with&lt;/P&gt;&lt;P&gt;imp_date_test = remove(imp_date,9);&lt;/P&gt;&lt;P&gt;before &lt;FONT face="courier new,courier"&gt;quit&lt;/FONT&gt;; within the sql procedure and got&amp;nbsp;error: 'Statement is not valid or it is used out of proper order'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Guessed I was not using the right function for the type of 'imp_date' but also got an error after adding the two lines below (before &lt;FONT face="courier new,courier"&gt;quit;&lt;/FONT&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;type_imp_date = type(imp_date);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%put &amp;amp;=type_imp_date; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please suggest the right way to do remove '202003' from imp_date and finding the type for imp_date?.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Sep 2021 10:49:44 GMT</pubDate>
    <dc:creator>maryami</dc:creator>
    <dc:date>2021-09-06T10:49:44Z</dc:date>
    <item>
      <title>Extracting elements from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-elements-from-a-macro-variable/m-p/766194#M242798</link>
      <description>&lt;P&gt;The sql procedure below (within a macro) generates a macro variable 'imp_date'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%macro imp_test;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;/* List of runs as macro variable */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;proc sql noprint; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;select cats(year(date),put(month(date),z2.)) into :imp_date separated by ' ' &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;from grid&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;where flag_qtr = 1 and date &amp;gt;= "&amp;amp;gen_date_first."d and date &amp;lt;= "&amp;amp;gen_date_last."d; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;quit;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;[...]&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%mend&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;,where&amp;nbsp;gen_date_first=31MAR2018,&amp;nbsp;gen_date_last=31DEC2020.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output:&lt;/P&gt;&lt;P&gt;IMP_DATE = 201803 201806 201809 201812 201903 201906 201909 201912 202003 202006 202009 202012&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I need to remove '202003' from imp_date, and tried with&lt;/P&gt;&lt;P&gt;imp_date_test = remove(imp_date,9);&lt;/P&gt;&lt;P&gt;before &lt;FONT face="courier new,courier"&gt;quit&lt;/FONT&gt;; within the sql procedure and got&amp;nbsp;error: 'Statement is not valid or it is used out of proper order'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Guessed I was not using the right function for the type of 'imp_date' but also got an error after adding the two lines below (before &lt;FONT face="courier new,courier"&gt;quit;&lt;/FONT&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;type_imp_date = type(imp_date);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%put &amp;amp;=type_imp_date; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please suggest the right way to do remove '202003' from imp_date and finding the type for imp_date?.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Sep 2021 10:49:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-elements-from-a-macro-variable/m-p/766194#M242798</guid>
      <dc:creator>maryami</dc:creator>
      <dc:date>2021-09-06T10:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting elements from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-elements-from-a-macro-variable/m-p/766195#M242799</link>
      <description>&lt;P&gt;Would it not make more sense to find the 9th element of data set GRID and work from there, instead of first creating and then working with a long macro variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, please, from now on, when you get an error in the LOG, show us the LOG for this PROC or DATA step. Do not show us error messages in the log that are disconnected from rest of the log and disconnected from the code that created them.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Sep 2021 11:31:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-elements-from-a-macro-variable/m-p/766195#M242799</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-06T11:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting elements from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-elements-from-a-macro-variable/m-p/766197#M242801</link>
      <description>&lt;P&gt;Thanks it was indeed easier to solve from the grid, submerged in the problem didn't look into the simplest solution!.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Sep 2021 11:34:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-elements-from-a-macro-variable/m-p/766197#M242801</guid>
      <dc:creator>maryami</dc:creator>
      <dc:date>2021-09-06T11:34:16Z</dc:date>
    </item>
  </channel>
</rss>

