<?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: Create a Variable from dataset in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731331#M35478</link>
    <description>&lt;P&gt;Thank you. Will try this out.&lt;BR /&gt;&lt;BR /&gt;Apologies, relatively new to SAS so will post correctly In future.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit:&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;Thank you - your suggestion worked.&lt;/P&gt;</description>
    <pubDate>Mon, 05 Apr 2021 20:51:01 GMT</pubDate>
    <dc:creator>mohamedk</dc:creator>
    <dc:date>2021-04-05T20:51:01Z</dc:date>
    <item>
      <title>Create a Variable from dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731172#M35455</link>
      <description>Hi All&lt;BR /&gt;&lt;BR /&gt;I’d like to create a variable or macro that includes info from an existing dataset.&lt;BR /&gt;&lt;BR /&gt;What I’m trying to achieve is to add a where clause to look at the info without having to write each one down all the time.&lt;BR /&gt;&lt;BR /&gt;Eg:&lt;BR /&gt;Data want;&lt;BR /&gt;Set have;&lt;BR /&gt;Where column in (column1);&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 03 Apr 2021 20:59:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731172#M35455</guid>
      <dc:creator>mohamedk</dc:creator>
      <dc:date>2021-04-03T20:59:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Variable from dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731174#M35457</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/328373"&gt;@mohamedk&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;I’d like to create a variable or macro that includes info from an existing dataset.&lt;BR /&gt;&lt;BR /&gt;What I’m trying to achieve is to add a where clause to look at the info without having to write each one down all the time.&lt;BR /&gt;&lt;BR /&gt;Eg:&lt;BR /&gt;Data want;&lt;BR /&gt;Set have;&lt;BR /&gt;Where column in (column1);&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm afraid I don't understand&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Where column in (column1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as this is not valid syntax in neither a DATA step nor in PROC SQL, and in my mind not valid logic here either. What is the logic you are trying to implement? Can you give simple examples?&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 21:48:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731174#M35457</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-03T21:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Variable from dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731176#M35458</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/328373"&gt;@mohamedk&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi All&lt;BR /&gt;&lt;BR /&gt;I’d like to create a variable or macro that includes info from an existing dataset.&lt;BR /&gt;&lt;BR /&gt;What I’m trying to achieve is to add a where clause to look at the info without having to write each one down all the time.&lt;BR /&gt;&lt;BR /&gt;Eg:&lt;BR /&gt;Data want;&lt;BR /&gt;Set have;&lt;BR /&gt;Where column in (column1);&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your "request" sounds like you want all the values for a variable. At which point a "where" is useless as by default you would get all the values.&lt;/P&gt;
&lt;P&gt;So you should provide a mite more detailed description such as example data, rules for selecting values from that data set and then we might have something that makes sense.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 22:42:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731176#M35458</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-03T22:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Variable from dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731256#M35466</link>
      <description>&lt;P&gt;For this to make sense you need to have two datasets.&amp;nbsp; One with the list of values your want to filter to.&amp;nbsp; For example a list of subjects or list of states etc.&amp;nbsp; The other is the dataset you want to analyze.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you could just merge the two.&amp;nbsp; If they are sorted already by that variable use a simple data step merge.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge have list(in=inlist);
  by subject ;
  if inlist;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could use SQL instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table want as
  select * 
  from have
  where subject in (select subject from list)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the list of values is smallish you could put them into a macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select distinct subject into :slist separated by ' '
from list
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note if the variable is character add quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select distinct quote(trim(subject)) into :slist separated by ' '
from list
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use the list in your WHERE clause.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have;
  where subject in (&amp;amp;slist);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Apr 2021 16:27:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731256#M35466</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-04T16:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Variable from dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731282#M35468</link>
      <description>&lt;P&gt;Apologies All,&lt;/P&gt;&lt;P&gt;It seems I was quite unclear in my questions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current query is:&lt;/P&gt;&lt;PRE&gt;proc sql;
create table test as 
select 
a.*,
b.field1,
b.field2,
b.field3
from tableA as a
LEFT JOIN 
	tableB as b ON a.CustomerNum = b.CustomerNum
where 
	b.field1 IN (123,456,789,010,111,212,131,415);&lt;BR /&gt;quit;

&lt;/PRE&gt;&lt;P&gt;I'd like to change the way I'm manually adding the numbers in the where clause to something less manual as currently I copied and pasted to test the logic of my query.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hoping the above makes more sense that my initial query&lt;BR /&gt;&lt;BR /&gt;cc:&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Apr 2021 21:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731282#M35468</guid>
      <dc:creator>mohamedk</dc:creator>
      <dc:date>2021-04-04T21:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Variable from dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731305#M35472</link>
      <description>&lt;P&gt;And where did you get the values that you manually entered in the list&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(123,456,789,010,111,212,131,415)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To "de-manual" this process of adding to this list, you need to tell us how these numeric values were established.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Apr 2021 03:04:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731305#M35472</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-04-05T03:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Variable from dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731319#M35474</link>
      <description>From a previous output</description>
      <pubDate>Mon, 05 Apr 2021 06:42:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731319#M35474</guid>
      <dc:creator>mohamedk</dc:creator>
      <dc:date>2021-04-05T06:42:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Variable from dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731322#M35475</link>
      <description>&lt;P&gt;By "output", do you mean "results" from some kind of reporting procedure, or a dataset created in a previous step?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Apr 2021 08:48:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731322#M35475</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-05T08:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Variable from dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731329#M35477</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/328373"&gt;@mohamedk&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;From a previous output&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So somehow, these numbers were in a previous output. What you ought to do is have the previous output store the numbers in a data set. Then, you can do something like this, where the variable name in the previous data set is ABC:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LEFT JOIN 
	tableB as b ON a.CustomerNum = b.CustomerNum
where 
	b.field1 IN (select distinct abc from mypreviousdataset);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;By the way, when you need help with SQL, don't start the thread by asking a DATA step question.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Apr 2021 10:26:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731329#M35477</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-05T10:26:24Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Variable from dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731331#M35478</link>
      <description>&lt;P&gt;Thank you. Will try this out.&lt;BR /&gt;&lt;BR /&gt;Apologies, relatively new to SAS so will post correctly In future.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit:&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;Thank you - your suggestion worked.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Apr 2021 20:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731331#M35478</guid>
      <dc:creator>mohamedk</dc:creator>
      <dc:date>2021-04-05T20:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Variable from dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731506#M35499</link>
      <description>&lt;P&gt;You can also use a hash for a lookup:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if _n_ = 1
then do;
  declare hash l (dataset:"previous (keep=field1)");
  l.definekey(field1);
  l.definedone();
end;
if l.check() = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Apr 2021 04:57:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-a-Variable-from-dataset/m-p/731506#M35499</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-06T04:57:49Z</dc:date>
    </item>
  </channel>
</rss>

