<?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: SAS MACROS question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-MACROS-question/m-p/767494#M243329</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might be better off describing the big picture of what you're doing.&amp;nbsp; My guess is there is non-macro solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just glancing at the code, and not really understanding what it's doing, I would think that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sql noprint;
select PARTY_NUMBER, STREET_COUNTRY_CODE into :pty_num1 -: pty_num&amp;amp;i.,
:cnty_cde1 -:cnty_cde&amp;amp;i. from cre.FSC_COUNTRY_DIM where
UPPER(country_code_3)=' ';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Should be before the %do block.&amp;nbsp; And maybe it should be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sql noprint;
select PARTY_NUMBER, STREET_COUNTRY_CODE into :pty_num1 -: pty_num&amp;amp;dnts.,
:cnty_cde1 -:cnty_cde&amp;amp;dnts. from cre.FSC_COUNTRY_DIM where
UPPER(country_code_3)=' ';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But again, if this is basically a data update problem, you might be better off with a MERGE or UPDATE step rather than writing values to macro variables and then writing them back to a dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Sep 2021 17:35:51 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2021-09-13T17:35:51Z</dc:date>
    <item>
      <title>SAS MACROS question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-MACROS-question/m-p/767470#M243320</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to update a table where the Country code 3 column is missing or null using the below macro. Kindly find the partial log after the macro;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe there is some issue with the way have written this macro because every time I run this macro I need to run it a couple of times to update all the missing records.&lt;/P&gt;&lt;P&gt;Kindly suggest.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;options Symbolgen Mlogic Mprint;&lt;/P&gt;&lt;P&gt;%macro ints;&lt;BR /&gt;Proc sql ;&lt;BR /&gt;select Count(*) into :dnts from cre.FSC_COUNTRY_DIM Where&lt;BR /&gt;UPPER(country_code_3)=' ';&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;dnts.;&lt;/P&gt;&lt;P&gt;%if &amp;amp;dnts. eq 0 %then&lt;BR /&gt;%do;&lt;BR /&gt;%put Note:Country DIM NOT EMPTY;&lt;BR /&gt;%end;&lt;BR /&gt;%else&lt;BR /&gt;%do;&lt;BR /&gt;%put &amp;amp;dnts.;&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;dnts.;&lt;/P&gt;&lt;P&gt;Proc sql noprint;&lt;BR /&gt;select PARTY_NUMBER, STREET_COUNTRY_CODE into :pty_num1 -: pty_num&amp;amp;i.,&lt;BR /&gt;:cnty_cde1 -:cnty_cde&amp;amp;i. from cre.FSC_COUNTRY_DIM where&lt;BR /&gt;UPPER(country_code_3)=' ';&lt;BR /&gt;quit;&lt;BR /&gt;%put PARTY_NUMBER&amp;amp;i.==&amp;gt;&amp;gt; &amp;amp;&amp;amp;cnty_cde&amp;amp;i.;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;update cre.FSC_COUNTRY_DIM set country_code_3="&amp;amp;&amp;amp;cnty_cde&amp;amp;i." where&lt;BR /&gt;PARTY_NUMBER="&amp;amp;&amp;amp;pty_num&amp;amp;i." and UPPER(country_code_3)=' ';&lt;BR /&gt;quit;&lt;BR /&gt;%put country_code_3&amp;amp;i.;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;%ints;&lt;/P&gt;&lt;P&gt;=========================================================&lt;/P&gt;&lt;P&gt;LOGS:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SYMBOLGEN: Macro variable I resolves to 7&lt;BR /&gt;SYMBOLGEN: Macro variable PTY_NUM7 resolves to 0000000000xxxxxXXXXXYY&lt;BR /&gt;MPRINT(INTS): update cre.FSC_COUNTRY_DIM set country_code_3="XXX" where PARTY_NUMBER="0000000000xxxxxXXXXXYY" and&lt;BR /&gt;UPPER(country_code_3)=' ';&lt;BR /&gt;NOTE: 1 row was updated in CRE.FSC_COUNTRY_DIM.&lt;BR /&gt;MPRINT(INTS): quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;&lt;P&gt;MLOGIC(INTS): %PUT country_code_3&amp;amp;i.&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 7&lt;BR /&gt;country_code_37&lt;BR /&gt;MLOGIC(INTS): %DO loop index variable I is now 8; loop will iterate again.&lt;BR /&gt;MPRINT(INTS): Proc sql noprint;&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 8&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 8&lt;BR /&gt;MPRINT(INTS): select PARTY_NUMBER, STREET_COUNTRY_CODE into :pty_num1 -: pty_num8, :cnty_cde1 -:cnty_cde8 from&lt;BR /&gt;cre.FSC_COUNTRY_DIM where UPPER(country_code_3)=' ';&lt;BR /&gt;MPRINT(INTS): ;&lt;BR /&gt;MPRINT(INTS): quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;MLOGIC(INTS): %PUT PARTY_NUMBER&amp;amp;i.==&amp;gt;&amp;gt; &amp;amp;&amp;amp;cnty_cde&amp;amp;i.&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 8&lt;BR /&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 8&lt;BR /&gt;WARNING: Apparent symbolic reference CNTY_CDE8 not resolved.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="sasLog"&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 16:25:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-MACROS-question/m-p/767470#M243320</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2021-09-13T16:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: SAS MACROS question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-MACROS-question/m-p/767476#M243324</link>
      <description>&lt;P&gt;Did you try writing it outside the macro prior to macrotizing it?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 16:53:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-MACROS-question/m-p/767476#M243324</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-09-13T16:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: SAS MACROS question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-MACROS-question/m-p/767494#M243329</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might be better off describing the big picture of what you're doing.&amp;nbsp; My guess is there is non-macro solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just glancing at the code, and not really understanding what it's doing, I would think that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sql noprint;
select PARTY_NUMBER, STREET_COUNTRY_CODE into :pty_num1 -: pty_num&amp;amp;i.,
:cnty_cde1 -:cnty_cde&amp;amp;i. from cre.FSC_COUNTRY_DIM where
UPPER(country_code_3)=' ';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Should be before the %do block.&amp;nbsp; And maybe it should be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sql noprint;
select PARTY_NUMBER, STREET_COUNTRY_CODE into :pty_num1 -: pty_num&amp;amp;dnts.,
:cnty_cde1 -:cnty_cde&amp;amp;dnts. from cre.FSC_COUNTRY_DIM where
UPPER(country_code_3)=' ';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But again, if this is basically a data update problem, you might be better off with a MERGE or UPDATE step rather than writing values to macro variables and then writing them back to a dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 17:35:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-MACROS-question/m-p/767494#M243329</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2021-09-13T17:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS MACROS question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-MACROS-question/m-p/767505#M243334</link>
      <description>&lt;P&gt;No need for to query twice to know how many macro variables you want to create.&amp;nbsp; SAS will stop when it runs out of observations.&amp;nbsp; And it will tell you how many it found in the automatic macro variable SQLOBS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a cleaned up version of your macro with some extra protection against special characters in the macro variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ints;
%local i dnts party country;

proc sql noprint;
  select distinct 
         PARTY_NUMBER
       , STREET_COUNTRY_CODE
    into :pty_num1-
       , :cnty_cde1-
  from cre.FSC_COUNTRY_DIM 
  where country_code_3=' '
;
%let dnts=&amp;amp;sqlobs;

%if &amp;amp;dnts. = 0 %then %do;
  %put NOTE: No empty values of COUNTRY_CODE found.;
%end; 
%else %do i=1 %to &amp;amp;dnts.;
  %let party = %sysfunc(quote(%superq(pty_num&amp;amp;i),%str(%'))) ;
  %let country = %sysfunc(quote(%superq(cnty_cde&amp;amp;i),%str(%'))) ;

update cre.FSC_COUNTRY_DIM 
  set country_code_3=&amp;amp;country
  where party_number=&amp;amp;party
    and country_code_3=' '
;
%end;

quit;

%mend;

%ints;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But really it looks like you just want to run this query.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
update cre.FSC_COUNTRY_DIM 
  set country_code_3=STREET_COUNTRY_CODE
  where country_code_3=' '
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Sep 2021 18:02:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-MACROS-question/m-p/767505#M243334</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-13T18:02:14Z</dc:date>
    </item>
  </channel>
</rss>

