<?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: Working with solved value of a macro parameter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811470#M320072</link>
    <description>&lt;PRE&gt;&lt;CODE class=""&gt;  %test(CurrentYear) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Macros (like %TEST) cannot access data step variables such as CURRENTYEAR.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps this is what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let currentyear=%sysfunc(datepart(%sysfunc(today())));

data kip ;
  %test(&amp;amp;currentyear)
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 May 2022 15:15:47 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-05-04T15:15:47Z</dc:date>
    <item>
      <title>Working with solved value of a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811469#M320071</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got the following code (simplified):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%MACRO test(y) ;
  year_&amp;amp;y. = 'hello' ;
%MEND ;

DATA work.kip ;
  CurrentYear = 2022 ;
  %test(CurrentYear) ;
RUN ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I get is that the macro creates a variable called "year_y" with the content "hello".&lt;/P&gt;&lt;P&gt;But what I would like to get is that the macro creates a variable called "year_2022" with the content "hello".&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Is there anyway of doing this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thierry&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 14:48:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811469#M320071</guid>
      <dc:creator>ThierryHerrie</dc:creator>
      <dc:date>2022-05-04T14:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: Working with solved value of a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811470#M320072</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;  %test(CurrentYear) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Macros (like %TEST) cannot access data step variables such as CURRENTYEAR.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps this is what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let currentyear=%sysfunc(datepart(%sysfunc(today())));

data kip ;
  %test(&amp;amp;currentyear)
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 15:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811470#M320072</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-04T15:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: Working with solved value of a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811471#M320073</link>
      <description>Thanks for your quick reply!&lt;BR /&gt;Is there a way to pass 2022 into the parameter of the macro?</description>
      <pubDate>Wed, 04 May 2022 14:54:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811471#M320073</guid>
      <dc:creator>ThierryHerrie</dc:creator>
      <dc:date>2022-05-04T14:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: Working with solved value of a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811472#M320074</link>
      <description>&lt;P&gt;My mistake&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;use this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let currentyear=%sysfunc(year(%sysfunc(today())));

data kip ;
  %test(&amp;amp;currentyear)
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 15:18:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811472#M320074</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-04T15:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Working with solved value of a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811474#M320076</link>
      <description>&lt;P&gt;But, since you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/86347"&gt;@ThierryHerrie&lt;/a&gt;&amp;nbsp;have stated this is a simplified version of the problem ... I feel compelled to point out what you are doing is usually considered a poor practice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Variable names should not contain calendar information such as year or year/month &lt;EM&gt;etc&lt;/EM&gt;. I believe you are going down a path that has a lot of drawbacks. You would be much better have having year as a data step variable, and other columns indicating the value of something in that year.&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 14:58:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811474#M320076</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-04T14:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: Working with solved value of a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811478#M320079</link>
      <description>&lt;P&gt;You cannot change the name of a variable after the data step has already started running.&lt;/P&gt;
&lt;P&gt;If you want the name to include the digit string 2022 then call the macro with that string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA work.kip ;
  CurrentYear = 2022 ;
  %test(2022 ) ;
RUN ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But why not just do this instead?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA work.kip ;
  CurrentYear = 2022 ;
  Message = 'hello';
RUN ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now the YEAR is in a variable and the text string 'hello' is in a variable.&lt;/P&gt;
&lt;P&gt;Then you could have dataset where CURRENTYEAR is not a constant (and does not need to be known in advance).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA work.kip ;
  input CurrentYear Message $20.;
cards;
2022 hello
2023 good-bye
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 May 2022 15:04:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811478#M320079</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-04T15:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: Working with solved value of a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811490#M320084</link>
      <description>I agree. Especially when this is something you would like to schedule or something like that.&lt;BR /&gt;&lt;BR /&gt;The endgoal here is to create (for a onetime analysis) a dataset with one row per application and an indicator per month whether the month is relevant or not. This can be one month, or multiple months.</description>
      <pubDate>Wed, 04 May 2022 16:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811490#M320084</guid>
      <dc:creator>ThierryHerrie</dc:creator>
      <dc:date>2022-05-04T16:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Working with solved value of a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811491#M320085</link>
      <description>&lt;P&gt;Inspired by the comments here I think I will use a transpose to create the column(s) with the year in the variable name.&lt;/P&gt;&lt;P&gt;So first create a (dummy) variable with the value “year_2022” and then use that variable as variable name in the transpose.&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 16:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811491#M320085</guid>
      <dc:creator>ThierryHerrie</dc:creator>
      <dc:date>2022-05-04T16:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: Working with solved value of a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811497#M320087</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/86347"&gt;@ThierryHerrie&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Inspired by the comments here I think I will use a transpose to create the column(s) with the year in the variable name.&lt;/P&gt;
&lt;P&gt;So first create a (dummy) variable with the value “year_2022” and then use that variable as variable name in the transpose.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Well, no&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't create year_2022 in the first place, and then no need to transpose&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 16:24:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811497#M320087</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-04T16:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: Working with solved value of a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811500#M320088</link>
      <description>I appreciate your concern, but I will &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;It is like a report where you have a column per month, except I would like the data in a table.&lt;BR /&gt;Cheers!</description>
      <pubDate>Wed, 04 May 2022 16:29:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811500#M320088</guid>
      <dc:creator>ThierryHerrie</dc:creator>
      <dc:date>2022-05-04T16:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: Working with solved value of a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811507#M320093</link>
      <description>&lt;P&gt;Create a variable called YEAR, with a value of 2022, not YEAR_2022. &lt;BR /&gt;&lt;BR /&gt;Then when you transpose use the PREFIX option to add the YEAR_ in front of the year. You can use the IDLABEL to have it displayed as 2022 in reports as well rather than YEAR_2022 in reports.&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 16:48:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811507#M320093</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-05-04T16:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: Working with solved value of a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811509#M320095</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/86347"&gt;@ThierryHerrie&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I appreciate your concern, but I will &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;It is like a report where you have a column per month, except I would like the data in a table.&lt;BR /&gt;Cheers!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hello,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/86347"&gt;@ThierryHerrie&lt;/a&gt;&amp;nbsp;this is a common mistake. You want a report with columns like 2021 and 2022 so you think you have to create a data set with calendar information in the variable names. Not true at all, and even though you CAN do it with calendar information in the variable names, it is not a good approach. The better approach is to have a long data set, with a variable named YEAR containing the actual year, and then use PROC REPORT to create the report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can show us a portion of your data as SAS data step code, and show us the desired report, we can show you better ways to go about this.&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 16:48:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-solved-value-of-a-macro-parameter/m-p/811509#M320095</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-04T16:48:46Z</dc:date>
    </item>
  </channel>
</rss>

