<?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 adding global variable to a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/adding-global-variable-to-a-dataset/m-p/521314#M141428</link>
    <description>&lt;P&gt;I want to add data that I get from another table and&amp;nbsp;store&amp;nbsp;in a variable to every row in a dataset. The resulting table2 should have a new column called "new_company" with the text "Ford - BMC" in every row. Right now I get 3 new columns named new_company, BMC and Ford but all columns are blank.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data company;
	length co_name $50.;
 	input co_name $ 1-50; 
 	datalines;
Ford - BMC 
;
run;

data table1;
	infile datalines;
	input did pgm_id user $ dttime DATETIME24.3; 
	format dttime DATETIME24.3;
	return;
	datalines;
8 63832680 DAN 23AUG2013:19:42:55.160
2 63832680 JAN 01AUG2013:19:20:58.785
6 63832680 DAN 22AUG2013:13:57:12.506
4 63832680 DAN 13AUG2013:19:29:39.578
7 63832680 DAN 23AUG2013:15:30:00.452
9 63832680 DAN 26AUG2013:20:29:40.386
1 63832680 BOB 14AUG2013:22:24:41.894
5 63832680 DAN 16AUG2013:18:40:52.547
3 63832680 DAN 08AUG2013:19:13:00.356
;
run;

%GLOBAL comp_name;
proc sql noprint;
	select distinct co_name into :comp_name from company;
quit;
%put company &amp;amp;comp_name.;

data work.table2;
	set work.table1;
	new_company=&amp;amp;comp_name.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;TIA&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 13 Dec 2018 22:54:22 GMT</pubDate>
    <dc:creator>dan999</dc:creator>
    <dc:date>2018-12-13T22:54:22Z</dc:date>
    <item>
      <title>adding global variable to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-global-variable-to-a-dataset/m-p/521314#M141428</link>
      <description>&lt;P&gt;I want to add data that I get from another table and&amp;nbsp;store&amp;nbsp;in a variable to every row in a dataset. The resulting table2 should have a new column called "new_company" with the text "Ford - BMC" in every row. Right now I get 3 new columns named new_company, BMC and Ford but all columns are blank.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data company;
	length co_name $50.;
 	input co_name $ 1-50; 
 	datalines;
Ford - BMC 
;
run;

data table1;
	infile datalines;
	input did pgm_id user $ dttime DATETIME24.3; 
	format dttime DATETIME24.3;
	return;
	datalines;
8 63832680 DAN 23AUG2013:19:42:55.160
2 63832680 JAN 01AUG2013:19:20:58.785
6 63832680 DAN 22AUG2013:13:57:12.506
4 63832680 DAN 13AUG2013:19:29:39.578
7 63832680 DAN 23AUG2013:15:30:00.452
9 63832680 DAN 26AUG2013:20:29:40.386
1 63832680 BOB 14AUG2013:22:24:41.894
5 63832680 DAN 16AUG2013:18:40:52.547
3 63832680 DAN 08AUG2013:19:13:00.356
;
run;

%GLOBAL comp_name;
proc sql noprint;
	select distinct co_name into :comp_name from company;
quit;
%put company &amp;amp;comp_name.;

data work.table2;
	set work.table1;
	new_company=&amp;amp;comp_name.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;TIA&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 22:54:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-global-variable-to-a-dataset/m-p/521314#M141428</guid>
      <dc:creator>dan999</dc:creator>
      <dc:date>2018-12-13T22:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: adding global variable to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-global-variable-to-a-dataset/m-p/521316#M141430</link>
      <description>Sorry about the way the code looks. It's the first time I've used the feature to insert sas code and it doesn't seem to have worked.</description>
      <pubDate>Thu, 13 Dec 2018 22:41:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-global-variable-to-a-dataset/m-p/521316#M141430</guid>
      <dc:creator>dan999</dc:creator>
      <dc:date>2018-12-13T22:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: adding global variable to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-global-variable-to-a-dataset/m-p/521321#M141435</link>
      <description>&lt;P&gt;put the macro var in double quotes:&lt;/P&gt;&lt;P&gt;new_company="&amp;amp;comp_name.";&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 22:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-global-variable-to-a-dataset/m-p/521321#M141435</guid>
      <dc:creator>johnsville</dc:creator>
      <dc:date>2018-12-13T22:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: adding global variable to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-global-variable-to-a-dataset/m-p/521324#M141438</link>
      <description>&lt;P&gt;Fixed your code. The key is once you've modified it in the pop up editor, do not modify again in the editor.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.table2;
	set work.table1;
	new_company=&amp;amp;comp_name.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is the portion that's problematic.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look at it and see what SAS see's:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#800080"&gt;*What you programmed;&lt;/FONT&gt;&lt;BR /&gt;new_company=&amp;amp;comp_name.;
&lt;FONT color="#800080"&gt;*What SAS sees;&lt;/FONT&gt;
new_company = Ford - BMC; &lt;STRONG&gt;&lt;FONT color="#800080"&gt;*ford and bmc would be interpreted as variables here, check your log for a warning;&lt;/FONT&gt;&lt;/STRONG&gt;
&lt;BR /&gt;&lt;FONT color="#800080"&gt;&lt;STRONG&gt;*What it should be;&lt;/STRONG&gt;&lt;/FONT&gt;
new_company = "&amp;amp;comp_name";
&lt;FONT color="#800080"&gt;&lt;STRONG&gt;*What SAS sees;&lt;/STRONG&gt;&lt;/FONT&gt;
new_company = "Ford - BMC";
&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1691"&gt;@dan999&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I want to add data that I get from another table and&amp;nbsp;store&amp;nbsp;in a variable to every row in a dataset. The resulting table2 should have a new column called "new_company" with the text "Ford - BMC" in every row. Right now I get 3 new columns named new_company, BMC and Ford but all columns are blank.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data company;
	length co_name $50.;
 	input co_name $ 1-50; 
 	datalines;
Ford - BMC 
;
run;

data table1;
	infile datalines;
	input did pgm_id user $ dttime DATETIME24.3; 
	format dttime DATETIME24.3;
	return;
	datalines;
8 63832680 DAN 23AUG2013:19:42:55.160
2 63832680 JAN 01AUG2013:19:20:58.785
6 63832680 DAN 22AUG2013:13:57:12.506
4 63832680 DAN 13AUG2013:19:29:39.578
7 63832680 DAN 23AUG2013:15:30:00.452
9 63832680 DAN 26AUG2013:20:29:40.386
1 63832680 BOB 14AUG2013:22:24:41.894
5 63832680 DAN 16AUG2013:18:40:52.547
3 63832680 DAN 08AUG2013:19:13:00.356
;
run;

%GLOBAL comp_name;
proc sql noprint;
	select distinct co_name into :comp_name from company;
quit;
%put company &amp;amp;comp_name.;

data work.table2;
	set work.table1;
	new_company=&amp;amp;comp_name.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;TIA&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 22:57:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-global-variable-to-a-dataset/m-p/521324#M141438</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-12-13T22:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: adding global variable to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-global-variable-to-a-dataset/m-p/521356#M141453</link>
      <description>&lt;P&gt;So simple. Thanks Reeza.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2018 02:24:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-global-variable-to-a-dataset/m-p/521356#M141453</guid>
      <dc:creator>dan999</dc:creator>
      <dc:date>2018-12-14T02:24:06Z</dc:date>
    </item>
  </channel>
</rss>

