<?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: Find the column that will provide the requested value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-the-column-that-will-provide-the-requested-value/m-p/697534#M213182</link>
    <description>&lt;P&gt;I know to do it with long structure but what is the way to do it with wide structure?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

Data ttt1;
input ID Criticalmon  ;
cards;
999 1906
888 1908
;
run;

Data ttt2;
input ID mon Y ;
cards;
999 1901 1
999 1902 3
999 1903 5
999 1904 7
999 1905 9 
999 1906 2 
999 1907 4 
999 1908 6
999 1909 12
999 1910 7
999 1911 9 
999 1912 4
888 1901 3
888 1902 5
888 1903 2 
888 1904 1
888 1905 6
888 1906 1
888 1907 2
888 1908 8
888 1909 9
888 1910 1
888 1911 8
888 1912 7
;
run;


PROC SQL;
	create table wanted  as
	select a.*,b.Y as criticalValue 	   
	from  ttt1 as a
	left join ttt2 as b
	on a.ID=b.ID and a.Criticalmon=b.mon
;
QUIT;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 09 Nov 2020 08:32:30 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2020-11-09T08:32:30Z</dc:date>
    <item>
      <title>Find the column that will provide the requested value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-column-that-will-provide-the-requested-value/m-p/697530#M213178</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to add a new column called "Value" that will get the value of column tYYMM.&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;Id=999,mon=t1906,so the value will be from column t1906 (2)&lt;/P&gt;
&lt;P&gt;Id=888,mon=t1908,so the value will be from column t1908 (3)&lt;/P&gt;
&lt;P&gt;Id=444,mon=t1903,so the value will be from column t1903 (9)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Rawtb;
input ID mon $ t1901 t1902 t1903 t1904 t1905 t1906 t1907 t1908 t1909 t1910 t1911 t1912;
cards;
999 t1906 1 3 5 7 9 2 4 6 2 7 9 4
888 t1908 3 5 2 1 6 1 2 3 9 1 8 7
444 t1903 8 5 9 1 4 1 2 6 9 1 2 3
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 08:18:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-column-that-will-provide-the-requested-value/m-p/697530#M213178</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-11-09T08:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: Find the column that will provide the requested value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-column-that-will-provide-the-requested-value/m-p/697534#M213182</link>
      <description>&lt;P&gt;I know to do it with long structure but what is the way to do it with wide structure?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

Data ttt1;
input ID Criticalmon  ;
cards;
999 1906
888 1908
;
run;

Data ttt2;
input ID mon Y ;
cards;
999 1901 1
999 1902 3
999 1903 5
999 1904 7
999 1905 9 
999 1906 2 
999 1907 4 
999 1908 6
999 1909 12
999 1910 7
999 1911 9 
999 1912 4
888 1901 3
888 1902 5
888 1903 2 
888 1904 1
888 1905 6
888 1906 1
888 1907 2
888 1908 8
888 1909 9
888 1910 1
888 1911 8
888 1912 7
;
run;


PROC SQL;
	create table wanted  as
	select a.*,b.Y as criticalValue 	   
	from  ttt1 as a
	left join ttt2 as b
	on a.ID=b.ID and a.Criticalmon=b.mon
;
QUIT;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Nov 2020 08:32:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-column-that-will-provide-the-requested-value/m-p/697534#M213182</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-11-09T08:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: Find the column that will provide the requested value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-column-that-will-provide-the-requested-value/m-p/697537#M213185</link>
      <description>&lt;P&gt;Here is a brute force approach. Simply iterate over all tXXXX variables until you find a match. Then leave the search and set value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Rawtb;
input ID mon $ t1901 t1902 t1903 t1904 t1905 t1906 t1907 t1908 t1909 t1910 t1911 t1912;
cards;
999 t1906 1 3 5 7 9 2 4 6 2 7 9 4
888 t1908 3 5 2 1 6 1 2 3 9 1 8 7
444 t1903 8 5 9 1 4 1 2 6 9 1 2 3
;
run;

data want;
   set Rawtb;
   array t t1901 - t1912;
   do over t;
      if vname(t) = mon then leave;
   end;
   value = t;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Nov 2020 08:39:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-column-that-will-provide-the-requested-value/m-p/697537#M213185</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-09T08:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: Find the column that will provide the requested value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-column-that-will-provide-the-requested-value/m-p/697582#M213206</link>
      <description>&lt;PRE&gt;Data Rawtb;
input ID mon $ t1901 t1902 t1903 t1904 t1905 t1906 t1907 t1908 t1909 t1910 t1911 t1912;
cards;
999 t1906 1 3 5 7 9 2 4 6 2 7 9 4
888 t1908 3 5 2 1 6 1 2 3 9 1 8 7
444 t1903 8 5 9 1 4 1 2 6 9 1 2 3
;
run;

data want;
   set Rawtb;
   value = vvaluex(mon);
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Nov 2020 11:45:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-column-that-will-provide-the-requested-value/m-p/697582#M213206</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-11-09T11:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Find the column that will provide the requested value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-column-that-will-provide-the-requested-value/m-p/697584#M213208</link>
      <description>&lt;P&gt;If you don't create these wide data sets, with year and month in the variable name, and you use a long data set, this is extremely easy to do.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Even if you adopt the very simple solution from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;, you still had to go through the effort of creating variables t1901 to t1912, which isn't necessary with a long data set.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 11:59:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-column-that-will-provide-the-requested-value/m-p/697584#M213208</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-09T11:59:23Z</dc:date>
    </item>
  </channel>
</rss>

