<?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: Insert macro variable value into select statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Insert-macro-variable-value-into-select-statement/m-p/824279#M325516</link>
    <description>&lt;P&gt;So you want to replace studyid in "dm" with a constant value, i don't think it is a good idea to manipulate the dm, but to create a new dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set dm;
  studyid = "&amp;amp;studyid";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 20 Jul 2022 04:51:02 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2022-07-20T04:51:02Z</dc:date>
    <item>
      <title>Insert macro variable value into select statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-macro-variable-value-into-select-statement/m-p/824223#M325475</link>
      <description>&lt;P&gt;Hi all,&lt;BR /&gt;From the below table, how to create studyid as macro variable in the demograpy datasets and update all vaue with newly updated study from %let statement.&lt;/P&gt;
&lt;P&gt;It is not working&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Input data&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;%let studyid='PAT_213_432';&lt;/P&gt;
&lt;P&gt;data dm;&lt;BR /&gt;input studyid $ age gender;&lt;BR /&gt;cards;&lt;BR /&gt;abc_12_21 23 1&lt;BR /&gt;bcd_12_29 23 2&lt;BR /&gt;abc_11_21 28 1&lt;BR /&gt;def_12_21 23 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table demograpy as&lt;BR /&gt;select &amp;amp;studyid, age, gender&lt;BR /&gt;from sdtm.dm;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Expected output&lt;/U&gt;&lt;BR /&gt;&lt;BR /&gt;studyid&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; age gender&lt;BR /&gt;PAT_213_432&amp;nbsp; &amp;nbsp; &amp;nbsp; 23 1&lt;BR /&gt;PAT_213_432&amp;nbsp; &amp;nbsp; &amp;nbsp; 23 2&lt;BR /&gt;PAT_213_432&amp;nbsp; &amp;nbsp; &amp;nbsp; 28 1&lt;BR /&gt;PAT_213_432&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;23 1&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 19:06:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-macro-variable-value-into-select-statement/m-p/824223#M325475</guid>
      <dc:creator>abraham1</dc:creator>
      <dc:date>2022-07-19T19:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: Insert macro variable value into select statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-macro-variable-value-into-select-statement/m-p/824227#M325479</link>
      <description>&lt;P&gt;&lt;SPAN&gt;When &amp;amp;studyid is resolved inside of PROC SQL, you get the code&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table demograpy as
select 'PAT_213_432', age, gender
from sdtm.dm;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;and so now I ask you ... is this legal working SAS code? If you typed this in without macro variables exactly as I have typed it above, would it work? What is wrong? Please answer without talking about macro variables: What part(s) of the code would you have to change so that it becomes legal working SAS code??&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 19:40:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-macro-variable-value-into-select-statement/m-p/824227#M325479</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-19T19:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: Insert macro variable value into select statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-macro-variable-value-into-select-statement/m-p/824228#M325480</link>
      <description>&lt;P&gt;I don't think that query makes sense. Your macro variable studyID has a variable value, in the SELECT statement that would be a variable name, not value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table demograpy as
select studyID, age, gender
from sdtm.dm
where studyID in (&amp;amp;studyID);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Personally, I'd name my variables differently to avoid this confusion. (note the removal of the library in this example). I'm assuming your code works and your DM data set is in a library (STDM) but the code posted creates a table DM in the work library instead.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let selected_studyid='PAT_213_432';

data dm;
input studyid $ age gender;
cards;
abc_12_21 23 1
bcd_12_29 23 2
abc_11_21 28 1
def_12_21 23 1
;
run;

proc sql;
create table demograpy as
select studyid, age, gender
from dm
where studyid in (selected_studyID);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jul 2022 19:40:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-macro-variable-value-into-select-statement/m-p/824228#M325480</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-19T19:40:12Z</dc:date>
    </item>
    <item>
      <title>Re: Insert macro variable value into select statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-macro-variable-value-into-select-statement/m-p/824279#M325516</link>
      <description>&lt;P&gt;So you want to replace studyid in "dm" with a constant value, i don't think it is a good idea to manipulate the dm, but to create a new dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set dm;
  studyid = "&amp;amp;studyid";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jul 2022 04:51:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-macro-variable-value-into-select-statement/m-p/824279#M325516</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-07-20T04:51:02Z</dc:date>
    </item>
    <item>
      <title>Re: Insert macro variable value into select statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-macro-variable-value-into-select-statement/m-p/824289#M325520</link>
      <description>&lt;P&gt;You need to give the value a variable name:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table demograpy as
select &amp;amp;studyid as studyid, age, gender
from sdtm.dm;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;proposes is best for your issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 06:38:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-macro-variable-value-into-select-statement/m-p/824289#M325520</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-07-20T06:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: Insert macro variable value into select statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-macro-variable-value-into-select-statement/m-p/824425#M325594</link>
      <description>&lt;P&gt;Thanks Everyone for the solution and guidance&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 17:32:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-macro-variable-value-into-select-statement/m-p/824425#M325594</guid>
      <dc:creator>abraham1</dc:creator>
      <dc:date>2022-07-20T17:32:03Z</dc:date>
    </item>
  </channel>
</rss>

