<?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: Uninitialized variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Uninitialized-variable/m-p/880532#M347903</link>
    <description>&lt;P&gt;In this data step you never give the variable a value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dates;
  datelastmonth = intnx('month',v_bus_dt,-1,'S');  
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Where is the value of V_BUS_DT supposed to come from?&amp;nbsp; Is it some other dataset?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so you forgot the SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you trying to use a macro variable named V_BUS_DT?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so you need to use &amp;amp; before the macro variable's name to have the macro processor insert its value into your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it looks like you are putting a STRING into the macro variable.&amp;nbsp; So that will not work with the INTNX() function as it wants a DATE value there.&amp;nbsp; Dates are NUMBERS and not STRINGS.&lt;/P&gt;</description>
    <pubDate>Tue, 13 Jun 2023 19:58:03 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-06-13T19:58:03Z</dc:date>
    <item>
      <title>Uninitialized variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Uninitialized-variable/m-p/880530#M347902</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am fairly new to SAS.&amp;nbsp; This is the piece of sas code that I am running.&amp;nbsp; I am trying to get the same date&amp;nbsp; previous month based on&amp;nbsp; the value fetched from the database.&lt;/P&gt;&lt;P&gt;========================================&lt;/P&gt;&lt;P&gt;%macro load_table_dly;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;%put &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; CONNECTING TO DB &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;;&lt;BR /&gt;connect to &amp;amp;prod_mba_driver(&amp;amp;prod_mba_db_connection_passthru user=&amp;amp;userid password=&amp;amp;passwd);&lt;BR /&gt;%put &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; EXTRACTING BUSINESS DATE FROM THE DB &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;;&lt;BR /&gt;select bus_dt&lt;BR /&gt;into :v_bus_dt&lt;BR /&gt;from connection to &amp;amp;prod_mba_driver&lt;BR /&gt;(select bus_dt&lt;BR /&gt;from (select ''''||coalesce(max(mech.bus_dt),cast(&amp;amp;db2_day0. as date))||'''' as bus_dt&lt;BR /&gt;from yyyyyyy as mech&lt;BR /&gt;where 1=1&lt;BR /&gt;and cast(mech.cad_run_dtm as date) = &amp;amp;db2_day0.&lt;BR /&gt;) as mx_dt&lt;BR /&gt;);&lt;BR /&gt;%put &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; DISCONNECTING FROM PROD_MBA &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;;&lt;BR /&gt;disconnect from &amp;amp;prod_mba_driver;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;=v_bus_dt;&amp;nbsp; &amp;nbsp;/*display the fetched date */&lt;BR /&gt;data dates;&lt;BR /&gt;datelastmonth = intnx('month',v_bus_dt,-1,'S');&amp;nbsp; /* Get the previous month, same date */&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%mend load_table_dly;&lt;BR /&gt;%load_table_dly;&lt;/P&gt;&lt;P&gt;==================================================&lt;/P&gt;&lt;P&gt;From the log file:&lt;/P&gt;&lt;P&gt;V_BUS_DT='2023-06-12'&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;NOTE: Variable v_bus_dt is uninitialized.&amp;nbsp; &amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Help appreciated&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 19:51:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Uninitialized-variable/m-p/880530#M347902</guid>
      <dc:creator>Sherry40</dc:creator>
      <dc:date>2023-06-13T19:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: Uninitialized variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Uninitialized-variable/m-p/880532#M347903</link>
      <description>&lt;P&gt;In this data step you never give the variable a value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dates;
  datelastmonth = intnx('month',v_bus_dt,-1,'S');  
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Where is the value of V_BUS_DT supposed to come from?&amp;nbsp; Is it some other dataset?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so you forgot the SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you trying to use a macro variable named V_BUS_DT?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so you need to use &amp;amp; before the macro variable's name to have the macro processor insert its value into your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it looks like you are putting a STRING into the macro variable.&amp;nbsp; So that will not work with the INTNX() function as it wants a DATE value there.&amp;nbsp; Dates are NUMBERS and not STRINGS.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 19:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Uninitialized-variable/m-p/880532#M347903</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-13T19:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: Uninitialized variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Uninitialized-variable/m-p/880533#M347904</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Replace the following:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data dates;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;datelastmonth = intnx('month',v_bus_dt,-1,'S');&amp;nbsp; /* Get the previous month, same date */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;With:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dates;
datelastmonth = intnx('month', input(&amp;amp;v_bus_dt, yymmdd10.),-1,'S');  /* Get the previous month, same date */
format datelastmonth yymmddd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/443827"&gt;@Sherry40&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am fairly new to SAS.&amp;nbsp; This is the piece of sas code that I am running.&amp;nbsp; I am trying to get the same date&amp;nbsp; previous month based on&amp;nbsp; the value fetched from the database.&lt;/P&gt;
&lt;P&gt;========================================&lt;/P&gt;
&lt;P&gt;%macro load_table_dly;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;%put &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; CONNECTING TO DB &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;;&lt;BR /&gt;connect to &amp;amp;prod_mba_driver(&amp;amp;prod_mba_db_connection_passthru user=&amp;amp;userid password=&amp;amp;passwd);&lt;BR /&gt;%put &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; EXTRACTING BUSINESS DATE FROM THE DB &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;;&lt;BR /&gt;select bus_dt&lt;BR /&gt;into :v_bus_dt&lt;BR /&gt;from connection to &amp;amp;prod_mba_driver&lt;BR /&gt;(select bus_dt&lt;BR /&gt;from (select ''''||coalesce(max(mech.bus_dt),cast(&amp;amp;db2_day0. as date))||'''' as bus_dt&lt;BR /&gt;from yyyyyyy as mech&lt;BR /&gt;where 1=1&lt;BR /&gt;and cast(mech.cad_run_dtm as date) = &amp;amp;db2_day0.&lt;BR /&gt;) as mx_dt&lt;BR /&gt;);&lt;BR /&gt;%put &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; DISCONNECTING FROM PROD_MBA &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;;&lt;BR /&gt;disconnect from &amp;amp;prod_mba_driver;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;=v_bus_dt;&amp;nbsp; &amp;nbsp;/*display the fetched date */&lt;BR /&gt;data dates;&lt;BR /&gt;datelastmonth = intnx('month',v_bus_dt,-1,'S');&amp;nbsp; /* Get the previous month, same date */&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%mend load_table_dly;&lt;BR /&gt;%load_table_dly;&lt;/P&gt;
&lt;P&gt;==================================================&lt;/P&gt;
&lt;P&gt;From the log file:&lt;/P&gt;
&lt;P&gt;V_BUS_DT='2023-06-12'&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;NOTE: Variable v_bus_dt is uninitialized.&amp;nbsp; &amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Help appreciated&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 20:01:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Uninitialized-variable/m-p/880533#M347904</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-06-13T20:01:06Z</dc:date>
    </item>
    <item>
      <title>Re: Uninitialized variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Uninitialized-variable/m-p/880535#M347906</link>
      <description>&lt;P&gt;Since this is occurring in macro code will you please&lt;/P&gt;
&lt;P&gt;1) place this line before where you run the macro :&lt;/P&gt;
&lt;PRE&gt;options mprint;&lt;/PRE&gt;
&lt;P&gt;2) Then run the macro and share the entire log and generated code. Copy from the log, on the forum open a text box by clicking on the &amp;lt;/&amp;gt; icon above the message window and then paste the text into the text box.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The option MPRINT will show details of the statements created by the macro processor, so we see much more detail of what actually occurs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One issue: Something like '2023-06-12' is not a valid value to use with any of the date functions. That is just a character value. Dates are numeric and represent the number of days since 01JAN1960. If you try to create a literal date value it appears as 'ddMONyy'd&amp;nbsp; The dd are the days of the month, MON is the three-letter abbreviation of the Month and yy is the year, best as 4 digits to avoid any possible confusion. The whole value is wrapped inside quotes and is immediately followed by a letter D to tell SAS you intend this to be a date value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You get uninitialized because in this statement:&lt;/P&gt;
&lt;PRE&gt;datelastmonth = intnx('month',v_bus_dt,-1,'S');  /* Get the previous month, same date */&lt;/PRE&gt;
&lt;P&gt;V_bus_dt is written as data step variable. Which you have not supplied as a variable in the data set so has no values assigned.&lt;/P&gt;
&lt;P&gt;with the shown macro variable you can get a date value to use with INTNX as&lt;/P&gt;
&lt;PRE&gt;datelastmonth = intnx('month',input(&amp;amp;v_bus_dt,yymmdd10.),-1,'S');  /* Get the previous month, same date */&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Jun 2023 20:05:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Uninitialized-variable/m-p/880535#M347906</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-06-13T20:05:42Z</dc:date>
    </item>
    <item>
      <title>Re: Uninitialized variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Uninitialized-variable/m-p/881396#M348268</link>
      <description>&lt;P&gt;Thank you all for the reply.&amp;nbsp; the 'input' command helped.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2023 14:02:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Uninitialized-variable/m-p/881396#M348268</guid>
      <dc:creator>Sherry40</dc:creator>
      <dc:date>2023-06-19T14:02:04Z</dc:date>
    </item>
  </channel>
</rss>

