<?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 Have troubles with data type conversions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Have-troubles-with-data-type-conversions/m-p/903492#M356992</link>
    <description>&lt;P&gt;Hi,&lt;BR /&gt;I have this code, where I need to change manually only the variable "l_bal_date" and other variables are calculated by the program:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/* Current balance variables */
%let l_bal_date='01sep2023'd;
%let vMonth     = %sysfunc(Month(&amp;amp;l_bal_date), z2.);
%let vYear_2d   = %sysfunc(PUTN(&amp;amp;l_bal_date, year2.), 2.);
%let vYear_4d   = %sysfunc(PUTN(&amp;amp;l_bal_date, year4.), 4.);
%let maz_date   = &amp;amp;vmonth.&amp;amp;vYear_2d;
%let mazan_path = &amp;amp;vYear_4d.-&amp;amp;vMonth;
%let file       = new_&amp;amp;vYear_4d.&amp;amp;vMonth;
%let file_new   = &amp;amp;file;
%let file_date  = &amp;amp;vYear_4d.&amp;amp;vMonth;
%let date_re    = &amp;amp;file_date;
%let sheet_name = "&amp;amp;maz_date";
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;After that I have this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Previous balance Dates */
%Let Prev_bal_date  = intnx('month', &amp;amp;Prev_bal_date, -3, 'b');
%let vMonth_prev    = %sysfunc(Month(&amp;amp;Prev_bal_date), z2.);
%let vYear_prev_2d  = %sysfunc(PUTN(&amp;amp;Prev_bal_date, year2.), 2.);
%let vYear_prev_4d  = %sysfunc(PUTN(&amp;amp;Prev_bal_date, year4.), 4.);
%let prev_maz_date  = &amp;amp;vMonth_prev.&amp;amp;vYear_prev_2d;
%let file_name="\\Folder\results_sas_final_movement_&amp;amp;vMonth_prev.-&amp;amp;maz_date.";
%let file_name_movement="\\Folder\results_sas_final_movement_meforat_&amp;amp;vMonth_prev.-&amp;amp;maz_date.";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Second part of the code returns Error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;56         /*Previous balance Dates */
57         %Let Prev_bal_date  = intnx('month', &amp;amp;Prev_bal_date, -3, 'b');
58         %let vMonth_prev    = %sysfunc(Month(&amp;amp;Prev_bal_date), z2.);
ERROR: Argument 1 to function MONTH referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list.  Execution of %SYSCALL statement or %SYSFUNC 
       or %QSYSFUNC function reference is terminated.
59         %let vYear_prev_2d  = %sysfunc(PUTN(&amp;amp;Prev_bal_date, year2.), 2.);
ERROR: Argument 1 to function PUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list.  Execution of %SYSCALL statement or %SYSFUNC 
       or %QSYSFUNC function reference is terminated.
60         %let vYear_prev_4d  = %sysfunc(PUTN(&amp;amp;Prev_bal_date, year4.), 4.);
ERROR: Argument 1 to function PUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list.  Execution of %SYSCALL statement or %SYSFUNC 
       or %QSYSFUNC function reference is terminated.
61         %let prev_maz_date  = &amp;amp;vMonth_prev.&amp;amp;vYear_prev_2d;
62         
63         %let file_name="\\Folder\results_sas_final_movement_&amp;amp;vMonth_prev.-&amp;amp;maz_date.";
64         %let file_name_movement="\\Folder\results_sas_final_movement_meforat_&amp;amp;vMonth_prev.-&amp;amp;maz_date.";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The Question:&lt;/P&gt;
&lt;P&gt;What I'm doing wrong and what I have to do to get "file_name" and "file_name_movement" with dates instead of variable names?&lt;/P&gt;</description>
    <pubDate>Thu, 16 Nov 2023 14:21:48 GMT</pubDate>
    <dc:creator>IgorR</dc:creator>
    <dc:date>2023-11-16T14:21:48Z</dc:date>
    <item>
      <title>Have troubles with data type conversions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Have-troubles-with-data-type-conversions/m-p/903492#M356992</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;I have this code, where I need to change manually only the variable "l_bal_date" and other variables are calculated by the program:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/* Current balance variables */
%let l_bal_date='01sep2023'd;
%let vMonth     = %sysfunc(Month(&amp;amp;l_bal_date), z2.);
%let vYear_2d   = %sysfunc(PUTN(&amp;amp;l_bal_date, year2.), 2.);
%let vYear_4d   = %sysfunc(PUTN(&amp;amp;l_bal_date, year4.), 4.);
%let maz_date   = &amp;amp;vmonth.&amp;amp;vYear_2d;
%let mazan_path = &amp;amp;vYear_4d.-&amp;amp;vMonth;
%let file       = new_&amp;amp;vYear_4d.&amp;amp;vMonth;
%let file_new   = &amp;amp;file;
%let file_date  = &amp;amp;vYear_4d.&amp;amp;vMonth;
%let date_re    = &amp;amp;file_date;
%let sheet_name = "&amp;amp;maz_date";
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;After that I have this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Previous balance Dates */
%Let Prev_bal_date  = intnx('month', &amp;amp;Prev_bal_date, -3, 'b');
%let vMonth_prev    = %sysfunc(Month(&amp;amp;Prev_bal_date), z2.);
%let vYear_prev_2d  = %sysfunc(PUTN(&amp;amp;Prev_bal_date, year2.), 2.);
%let vYear_prev_4d  = %sysfunc(PUTN(&amp;amp;Prev_bal_date, year4.), 4.);
%let prev_maz_date  = &amp;amp;vMonth_prev.&amp;amp;vYear_prev_2d;
%let file_name="\\Folder\results_sas_final_movement_&amp;amp;vMonth_prev.-&amp;amp;maz_date.";
%let file_name_movement="\\Folder\results_sas_final_movement_meforat_&amp;amp;vMonth_prev.-&amp;amp;maz_date.";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Second part of the code returns Error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;56         /*Previous balance Dates */
57         %Let Prev_bal_date  = intnx('month', &amp;amp;Prev_bal_date, -3, 'b');
58         %let vMonth_prev    = %sysfunc(Month(&amp;amp;Prev_bal_date), z2.);
ERROR: Argument 1 to function MONTH referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list.  Execution of %SYSCALL statement or %SYSFUNC 
       or %QSYSFUNC function reference is terminated.
59         %let vYear_prev_2d  = %sysfunc(PUTN(&amp;amp;Prev_bal_date, year2.), 2.);
ERROR: Argument 1 to function PUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list.  Execution of %SYSCALL statement or %SYSFUNC 
       or %QSYSFUNC function reference is terminated.
60         %let vYear_prev_4d  = %sysfunc(PUTN(&amp;amp;Prev_bal_date, year4.), 4.);
ERROR: Argument 1 to function PUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list.  Execution of %SYSCALL statement or %SYSFUNC 
       or %QSYSFUNC function reference is terminated.
61         %let prev_maz_date  = &amp;amp;vMonth_prev.&amp;amp;vYear_prev_2d;
62         
63         %let file_name="\\Folder\results_sas_final_movement_&amp;amp;vMonth_prev.-&amp;amp;maz_date.";
64         %let file_name_movement="\\Folder\results_sas_final_movement_meforat_&amp;amp;vMonth_prev.-&amp;amp;maz_date.";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The Question:&lt;/P&gt;
&lt;P&gt;What I'm doing wrong and what I have to do to get "file_name" and "file_name_movement" with dates instead of variable names?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2023 14:21:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Have-troubles-with-data-type-conversions/m-p/903492#M356992</guid>
      <dc:creator>IgorR</dc:creator>
      <dc:date>2023-11-16T14:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Have troubles with data type conversions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Have-troubles-with-data-type-conversions/m-p/903496#M356994</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let Prev_bal_date  = intnx('month', &amp;amp;Prev_bal_date, -3, 'b');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro commands like %let cannot use INTNX, unless it is within %SYSFUNC.&amp;nbsp; Also, within %SYSFUNC you don't put quotes around text. So this might work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let Prev_bal_date  = %sysfunc(intnx(month, &amp;amp;Prev_bal_date, -3, b));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but still there are problems since &amp;amp;prev_bal_date doesn't seem to have been assigned a value. So it won't work unless &amp;amp;prev_bal_date has been assigned a value (in code you have not shown us), and then &amp;amp;prev_bal_date MUST be a valid SAS date value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, get out of the habit of treating dates as strings that have to be pulled apart and combined into desirable appearances.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let maz_date   = &amp;amp;vmonth.&amp;amp;vYear_2d;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is an example of pulling a string apart and combining it, and is unnecessary. If you have a macro variable with a valid SAS date value, you can obtain MMYY with the proper format applied to the macro variable with a valid SAS date value. So this would work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let l_bal_date=%sysevalf('01sep2023'd); /* &amp;amp;L_BAL_DATE is a valid SAS date */
%let maz_date=%sysfunc(putn(&amp;amp;l_bal_date,mmyyn4.)); /* Use format on valid SAS date value */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and now &amp;amp;maz_date is equal to 0923 without pulling strings apart and recombining them.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2023 20:22:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Have-troubles-with-data-type-conversions/m-p/903496#M356994</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-11-16T20:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: Have troubles with data type conversions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Have-troubles-with-data-type-conversions/m-p/903527#M357001</link>
      <description>&lt;P&gt;You passed the MONTH() function a string that started with the letters intnx.&amp;nbsp; It was expecting a numeric date value.&lt;/P&gt;
&lt;P&gt;I suspect you wanted the macro processor to actually run the INTNX() function instead of just building a string that could by used to generate SAS code that would run that function.&lt;/P&gt;
&lt;P&gt;You already appear familiar with using %SYSFUNC() to run SAS functions in macro code, so just do it here also.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let Prev_bal_date  = %sysfunc(intnx(month, &amp;amp;Prev_bal_date, -3, b));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2023 17:08:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Have-troubles-with-data-type-conversions/m-p/903527#M357001</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-16T17:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: Have troubles with data type conversions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Have-troubles-with-data-type-conversions/m-p/903858#M357126</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;It was very helpful.&lt;/P&gt;
&lt;P&gt;The purpose of the code I provided&amp;nbsp; is to build names of files to export data from my datasets (in very old SAS program that I'm trying to improve step by step).&lt;/P&gt;
&lt;P&gt;Till now I had to input every file name manually, and now I'm doing it automatically, based on single variable with date type.&lt;/P&gt;
&lt;P&gt;But I still confused about difference between:&lt;/P&gt;
&lt;P&gt;%let Var = 0923 and %let Var = "0923".&lt;/P&gt;
&lt;P&gt;Which format is preferable to use within strings?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2023 07:27:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Have-troubles-with-data-type-conversions/m-p/903858#M357126</guid>
      <dc:creator>IgorR</dc:creator>
      <dc:date>2023-11-20T07:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: Have troubles with data type conversions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Have-troubles-with-data-type-conversions/m-p/903907#M357136</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/446395"&gt;@IgorR&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;It was very helpful.&lt;/P&gt;
&lt;P&gt;The purpose of the code I provided&amp;nbsp; is to build names of files to export data from my datasets (in very old SAS program that I'm trying to improve step by step).&lt;/P&gt;
&lt;P&gt;Till now I had to input every file name manually, and now I'm doing it automatically, based on single variable with date type.&lt;/P&gt;
&lt;P&gt;But I still confused about difference between:&lt;/P&gt;
&lt;P&gt;%let Var = 0923 and %let Var = "0923".&lt;/P&gt;
&lt;P&gt;Which format is preferable to use within strings?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It depends on how you want to USE the value the of the macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to use it directly to generate part of string, such when building a filename, then you don't want the quotes in the value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var=0923;
filename indata "/mydir/myprefix&amp;amp;var..txt";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to use to generate SAS code then the quotes might make it easier.&amp;nbsp; Since the quoted digits will look like a string literal to SAS, but the unquoted digits would look like a number.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var="0923";
data want;
  length fname $200;
  fname=cats('/mydir/myprefix',&amp;amp;var,'.txt');
  infile indate&amp;nbsp;filevar=fname&amp;nbsp;;
...&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Nov 2023 14:03:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Have-troubles-with-data-type-conversions/m-p/903907#M357136</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-20T14:03:01Z</dc:date>
    </item>
  </channel>
</rss>

