<?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: Macro &amp;amp; SQL Update. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-amp-SQL-Update/m-p/829147#M327571</link>
    <description>&lt;P&gt;Why so complicated?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select value into :username from SASHelp.vmacro where name = 'sysuserid'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is equivalent to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let username = &amp;amp;sysuserid.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you can directly use SYSUSERID in your SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc SQL;
update table1
set Username = "&amp;amp;sysuserid."
where id = &amp;amp;id.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SQL statements are executed immediately, so no RUN is needed, but a QUIT to end the procedure.&lt;/P&gt;</description>
    <pubDate>Thu, 18 Aug 2022 04:44:24 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-08-18T04:44:24Z</dc:date>
    <item>
      <title>Macro &amp; SQL Update.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-amp-SQL-Update/m-p/829127#M327562</link>
      <description>&lt;P&gt;%macro Update_table(a, id, c) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;prc sql noprint ;&lt;/P&gt;&lt;P&gt;select id into :id&amp;nbsp;&amp;nbsp;from libnew.table1 where program="&amp;amp;a"&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select value into :username from SASHelp.vmacro where name = 'sysuserid'&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%put &amp;amp;username;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc SQL;&lt;/P&gt;&lt;P&gt;update table1&lt;/P&gt;&lt;P&gt;set Username = &amp;amp;username&lt;/P&gt;&lt;P&gt;where id = &amp;amp;id.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend&amp;nbsp;Update_table;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue is I want to use &lt;STRONG&gt;:username &lt;/STRONG&gt;result value with my update. I just want to know what's the best way to use :username variable in the update so I can update the value stored in the username variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2022 21:44:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-amp-SQL-Update/m-p/829127#M327562</guid>
      <dc:creator>dhavalyparikh</dc:creator>
      <dc:date>2022-08-17T21:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: Macro &amp; SQL Update.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-amp-SQL-Update/m-p/829129#M327563</link>
      <description>&lt;P&gt;Given the variables you are trying to update are character then they need to be enclosed in double quotes to resolve correctly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Update_table(a, id, c) ;

prc sql noprint ;
select id into :id  from libnew.table1 where program="&amp;amp;a"
select value into :username from SASHelp.vmacro where name = 'sysuserid'
run;

%put &amp;amp;username;


Proc SQL;
update table1
set Username = "&amp;amp;username"
where id = "&amp;amp;id.";
run;

%mend Update_table;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Aug 2022 01:15:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-amp-SQL-Update/m-p/829129#M327563</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-08-18T01:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: Macro &amp; SQL Update.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-amp-SQL-Update/m-p/829147#M327571</link>
      <description>&lt;P&gt;Why so complicated?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select value into :username from SASHelp.vmacro where name = 'sysuserid'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is equivalent to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let username = &amp;amp;sysuserid.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you can directly use SYSUSERID in your SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc SQL;
update table1
set Username = "&amp;amp;sysuserid."
where id = &amp;amp;id.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SQL statements are executed immediately, so no RUN is needed, but a QUIT to end the procedure.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Aug 2022 04:44:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-amp-SQL-Update/m-p/829147#M327571</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-08-18T04:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro &amp; SQL Update.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-amp-SQL-Update/m-p/829178#M327583</link>
      <description>You could use the following to check the list of all the system macro variable, And refer it directly :&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%put _all_;&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;=SYSUSERID ;</description>
      <pubDate>Thu, 18 Aug 2022 12:21:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-amp-SQL-Update/m-p/829178#M327583</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-08-18T12:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: Macro &amp; SQL Update.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-amp-SQL-Update/m-p/829197#M327593</link>
      <description>&lt;P&gt;If you want the value of SYSUSERID then just reference it directly. No need to run any queries.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc SQL;
update table1
  set Username = "&amp;amp;sysuserid"
  where id in (select id from libnew.table1 where program="&amp;amp;a")
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you could also just use the SQL keyword USER.&amp;nbsp; &amp;nbsp;That will have the same value as SYSUSERID.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc SQL;
update table1
  set Username = USER
  where id in (select id from libnew.table1 where program="&amp;amp;a")
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Aug 2022 13:31:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-amp-SQL-Update/m-p/829197#M327593</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-18T13:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: Macro &amp; SQL Update.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-amp-SQL-Update/m-p/829229#M327601</link>
      <description>&lt;P&gt;Thanks. That works!&lt;/P&gt;</description>
      <pubDate>Thu, 18 Aug 2022 15:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-amp-SQL-Update/m-p/829229#M327601</guid>
      <dc:creator>dhavalyparikh</dc:creator>
      <dc:date>2022-08-18T15:54:45Z</dc:date>
    </item>
  </channel>
</rss>

