<?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: Finding all the variables that have a particular value in the dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-all-the-variables-that-have-a-particular-value-in-the/m-p/717719#M221991</link>
    <description>&lt;P&gt;There is nothing in&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;code that is limiting what numeric variables it considers.&amp;nbsp; The only reference to K1-K6 was in the data step she used to make some sample data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS If you provide your own example data as a data step in your questions then people trying to help you won't need to make their own.&lt;/P&gt;</description>
    <pubDate>Mon, 08 Feb 2021 20:03:54 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-02-08T20:03:54Z</dc:date>
    <item>
      <title>Finding all the variables that have a particular value in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-all-the-variables-that-have-a-particular-value-in-the/m-p/717660#M221963</link>
      <description>&lt;P&gt;Hello, I have a dataset test which has 7000 variables. I have a task to find all the variables that have .B and .C in it. For example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;input K1 K2 K3 K4 K5;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 0&amp;nbsp; .B&amp;nbsp; 2&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;0&amp;nbsp; 2&amp;nbsp; &amp;nbsp;2&amp;nbsp; .C 0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 1&amp;nbsp; &amp;nbsp;1&amp;nbsp; 1&amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output should give me K3,K4 vars. I have tried creating an array and do loop as below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data tmp1;&lt;BR /&gt;set test;&lt;BR /&gt;array formats[*] _all_;&lt;/P&gt;&lt;P&gt;do i = 1 to dim(formats);&lt;BR /&gt;if formats[i] in (.B,.C)&amp;nbsp; ;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above code is giving me the observations that have .B and .C . Can anyone help me in directing the right way to get ONLY the list of variables that have .B and .C. Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 17:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-all-the-variables-that-have-a-particular-value-in-the/m-p/717660#M221963</guid>
      <dc:creator>sasquestions</dc:creator>
      <dc:date>2021-02-08T17:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Finding all the variables that have a particular value in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-all-the-variables-that-have-a-particular-value-in-the/m-p/717665#M221966</link>
      <description>&lt;P&gt;Is this what you want?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set test;
	array vars [*] k:;
		do i = 1 to dim(vars);
			if vars[i] in (".B", ".C") then flag = 1;
		end;
	drop i;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Feb 2021 17:30:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-all-the-variables-that-have-a-particular-value-in-the/m-p/717665#M221966</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-02-08T17:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: Finding all the variables that have a particular value in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-all-the-variables-that-have-a-particular-value-in-the/m-p/717672#M221970</link>
      <description>&lt;P&gt;I want the variables that have the particular value. The above code gives me the observations. Is there a way to find the list of variables ? Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 17:42:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-all-the-variables-that-have-a-particular-value-in-the/m-p/717672#M221970</guid>
      <dc:creator>sasquestions</dc:creator>
      <dc:date>2021-02-08T17:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: Finding all the variables that have a particular value in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-all-the-variables-that-have-a-particular-value-in-the/m-p/717673#M221971</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set test;
	array vars [*] k:;
		do i = 1 to dim(vars);
			if vars[i] in (".B", ".C") then var_of_interest = vname(vars[i]);
		end;
	drop i;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs K1 K2 K3 K4 K5 var_of_interest 
1 1 0 B 2 1 K3 
2 0 2 2 C 0 K4 
3 2 1 1 1 0   
&lt;/PRE&gt;
&lt;P&gt;Is that what you mean?&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 17:49:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-all-the-variables-that-have-a-particular-value-in-the/m-p/717673#M221971</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-02-08T17:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: Finding all the variables that have a particular value in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-all-the-variables-that-have-a-particular-value-in-the/m-p/717674#M221972</link>
      <description>&lt;P&gt;Here are two different ways. The first uses a data step and loops through the array, Every time it encounters a missing value it outputs that variable name to a data set and then you can remove duplicates after.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data singleStep;
	set test;
	array K(*) k1-k5;

	do i=1 to dim(k);

		if k(i) in (.B, .C) then
			do;
				variableName=vname(k(i));
				output;
			end;
	end;
	keep variableName;
run;

proc sort data=singleStep nodupkey;
	by variableName;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is more of a dynamic approach, that uses a format to map the values of interest to one group and everything else to another group. Then you summarize and see which variables have the values of interest. The method above is probably simpler but this works as well and puts the list of variables into a comma separated macro variable at the end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
	value find_fmt
.B, .C='Found' other='Not of Interest';
run;

*summarize into missing/not missing/
ods select none;
ods output onewayfreqs=summary;

proc freq data=test;
	table _all_ / missing;
	format _numeric_ find_fmt.;
run;

ods select all;
*Format output - probably more than is needed by code that I already have;

data want;
	length variable $32. variable_value $50.;
	set summary;
	Variable=scan(table, 2);
	Variable_Value=strip(trim(vvaluex(variable)));
	keep variable variable_value frequency percent cum:;
	label variable='Variable' variable_value='Variable Value';
run;

proc sql;
	select distinct variable Into :var_list separated by ", " from want where 
		variable_value="Found";
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 17:51:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-all-the-variables-that-have-a-particular-value-in-the/m-p/717674#M221972</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-08T17:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: Finding all the variables that have a particular value in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-all-the-variables-that-have-a-particular-value-in-the/m-p/717675#M221973</link>
      <description>I will Try this way. Thanks.</description>
      <pubDate>Mon, 08 Feb 2021 17:52:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-all-the-variables-that-have-a-particular-value-in-the/m-p/717675#M221973</guid>
      <dc:creator>sasquestions</dc:creator>
      <dc:date>2021-02-08T17:52:24Z</dc:date>
    </item>
    <item>
      <title>Re: Finding all the variables that have a particular value in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-all-the-variables-that-have-a-particular-value-in-the/m-p/717718#M221990</link>
      <description>&lt;P&gt;Thank you for the explanation. It worked.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 22:49:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-all-the-variables-that-have-a-particular-value-in-the/m-p/717718#M221990</guid>
      <dc:creator>sasquestions</dc:creator>
      <dc:date>2021-02-08T22:49:20Z</dc:date>
    </item>
    <item>
      <title>Re: Finding all the variables that have a particular value in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-all-the-variables-that-have-a-particular-value-in-the/m-p/717719#M221991</link>
      <description>&lt;P&gt;There is nothing in&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;code that is limiting what numeric variables it considers.&amp;nbsp; The only reference to K1-K6 was in the data step she used to make some sample data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS If you provide your own example data as a data step in your questions then people trying to help you won't need to make their own.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 20:03:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-all-the-variables-that-have-a-particular-value-in-the/m-p/717719#M221991</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-08T20:03:54Z</dc:date>
    </item>
  </channel>
</rss>

