<?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: Macro Loop for 2000 Columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225465#M40474</link>
    <description>from the proc freq output, the macro generates it.&lt;BR /&gt;&lt;BR /&gt;At the bottom of the code is an example of how to execute the macro, but I'll admit the documentation is non existent.</description>
    <pubDate>Mon, 14 Sep 2015 21:38:36 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2015-09-14T21:38:36Z</dc:date>
    <item>
      <title>Macro Loop for 2000 Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225443#M40462</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I take a data with 2000 columns. Names of the columns are like q1,q2,q3.... I want to create a new table with the ones that have the&lt;STRONG&gt; &amp;nbsp;count of non missing(+zero) rows&lt;/STRONG&gt; more than 70% in the column. &lt;STRONG&gt;I also want to join the some column whose percentage is less than 70 to the table&lt;/STRONG&gt;. My question is , how do i get 2000 output for 2000 columns with a single program and how do i specify and add the column to be created to the data.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The table that I want to create should look like the one below.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Q1 resultPercantage&lt;/P&gt;&lt;P&gt;Q2&amp;nbsp;&lt;SPAN&gt;resultPercantage&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Q3&amp;nbsp;&lt;SPAN&gt;resultPercantage&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There are also some codes that I tried to create below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;%LET VARNAME =&lt;/P&gt;&lt;P&gt;Column1/*Q1*/&lt;/P&gt;&lt;P&gt;Column2/*Q2*/&lt;/P&gt;&lt;P&gt;Column3/*Q3*/&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;percentage&lt;/EM&gt;&lt;/STRONG&gt;(&lt;STRONG&gt;0.70&lt;/STRONG&gt;)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; procfreq(Var);&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&amp;nbsp;percentage(deger);&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;Create Table new&amp;nbsp;as&lt;/P&gt;&lt;P&gt;SELECT (tt.nonMissingCount/tt.toplamCount) as result&amp;nbsp;format=percent10.2,&lt;/P&gt;&lt;P&gt;case&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;when calculated result&amp;gt;&amp;amp;deger then out=yeni /*????*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else 'false /*????*/'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end as yeniSonuc&lt;/P&gt;&lt;P&gt;from(&lt;/P&gt;&lt;P&gt;SELECT DISTINCT&lt;/P&gt;&lt;P&gt;(SELECT COUNT(&amp;amp;Var) as NonMissing from work.exampledata WHERE &amp;amp;Var ne &lt;STRONG&gt;0&lt;/STRONG&gt;) as nonMissingCount&lt;/P&gt;&lt;P&gt;,(SELECT COUNT(&amp;amp;Var) as SumCnt from work.exampedata) as sumCount from work.exampledata)as tt;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; &lt;STRONG&gt;&lt;EM&gt;loop&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;%let i=1;&lt;/P&gt;&lt;P&gt;%do %while(%scan(&amp;amp;VARNAME.,&amp;amp;i.,%STR( ))~=);&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;procfreq&lt;/EM&gt;&lt;/STRONG&gt;(%scan(&amp;amp;VARNAME.,&amp;amp;i.,%STR( )));&lt;/P&gt;&lt;P&gt;%let i=&amp;amp;i.+1;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;loop&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will be very greatful if I hear from you as soon as possible.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 21:59:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225443#M40462</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-09-14T21:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop for 2000 Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225445#M40464</link>
      <description>I doubt this is efficient but here's my macro:&lt;BR /&gt;&lt;A href="https://gist.github.com/statgeek/c3a9ddcb002c469e9d61" target="_blank"&gt;https://gist.github.com/statgeek/c3a9ddcb002c469e9d61&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Another way might be to transpose your data so you have a column identifying the variable and then the value and run a single proc sql or proc freq.</description>
      <pubDate>Mon, 14 Sep 2015 19:57:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225445#M40464</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-09-14T19:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop for 2000 Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225460#M40470</link>
      <description>&lt;P&gt;Where this &lt;STRONG&gt;count&lt;/STRONG&gt; value comes from ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Number_Missing=&amp;amp;obs_count-&lt;STRONG&gt;count&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 21:31:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225460#M40470</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-09-14T21:31:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop for 2000 Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225464#M40473</link>
      <description>Show example data. What you have followed by what you want to see.</description>
      <pubDate>Mon, 14 Sep 2015 21:37:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225464#M40473</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2015-09-14T21:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop for 2000 Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225465#M40474</link>
      <description>from the proc freq output, the macro generates it.&lt;BR /&gt;&lt;BR /&gt;At the bottom of the code is an example of how to execute the macro, but I'll admit the documentation is non existent.</description>
      <pubDate>Mon, 14 Sep 2015 21:38:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225465#M40474</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-09-14T21:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop for 2000 Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225478#M40475</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are 4000 numbers of Q columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/115i9B087A32C97D8495/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="sample.png" title="sample.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to see all of them percentage like below then i need to transpose it&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/116i717AD4CA1F163B0D/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Q1.png" title="Q1.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Q1 87.50%;&lt;/P&gt;&lt;P&gt;Q2 50&lt;SPAN&gt;.50%;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Q3 40&lt;SPAN&gt;.50%;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Q4 90&lt;SPAN&gt;.50%;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Q5 65&lt;SPAN&gt;.50%;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Q6 70&lt;SPAN&gt;.50%;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Q7 60&lt;SPAN&gt;.50%;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Q8&amp;nbsp;&lt;SPAN&gt;80.50%;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 21:56:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225478#M40475</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-09-14T21:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop for 2000 Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225482#M40477</link>
      <description>&lt;P&gt;It looks like you're in EG?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Use Tasks&amp;gt;Transpose and switch your data structure such that it becomes&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID Question Value&lt;/P&gt;&lt;P&gt;1 Q1 1&lt;/P&gt;&lt;P&gt;1 Q2 0&lt;/P&gt;&lt;P&gt;1 Q3 1&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 Q5000 0&lt;/P&gt;&lt;P&gt;2 Q1 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then use Query Builder with an N() and NMISS() function to determine the number of missing with the Question in the GROUP By Column.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 22:16:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225482#M40477</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-09-14T22:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop for 2000 Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225484#M40478</link>
      <description>&lt;P&gt;Thanks Reeza, i'll check. On the other hand your code involves a lot of things. I just a little bit confused( &lt;A href="https://gist.github.com/statgeek/c3a9ddcb002c469e9d61" target="_blank"&gt;https://gist.github.com/statgeek/c3a9ddcb002c469e9d61&lt;/A&gt; &amp;nbsp;) Can you show me a&amp;nbsp;simpler method to reach my loop and nonmissing aim,please .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank &amp;nbsp;you.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 22:29:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225484#M40478</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-09-14T22:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop for 2000 Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225517#M40495</link>
      <description>&lt;P&gt;You do not need macro code, much less a maco loop.&lt;/P&gt;&lt;P&gt;Look at this question that just used PROC FREQ to generate the counts for ALL variables.&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Missing-Values-for-character-variables/m-p/209244#M38823" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Missing-Values-for-character-variables/m-p/209244#M38823&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2015 06:10:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225517#M40495</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-09-15T06:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop for 2000 Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225551#M40505</link>
      <description>&lt;P&gt;This code will create a table with one row for each column and the %age of records with a &amp;gt;0 value; &amp;nbsp;any splitting of records with &amp;gt;70% etc can then easily be accomplished.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let colCnt=2000;
data out_data(keep=var pcntage);
	format pcntage percent7.2;
    array t t1-t&amp;amp;colCnt.;
	retain t1-t&amp;amp;colCnt. 0;  * retain some total counts;
	set x end = eof;
		array q q1-q&amp;amp;colCnt.;
		do i=1 to &amp;amp;colcnt;
		    t(i)=t(i)+(q(i)&amp;gt;0);  * add each non-missing to the total count ;
		end;
		if eof then do i=1 to &amp;amp;colcnt.;
			var='q'||strip(put(i,best.));  * create column name ;
			pcntage=t(i)/_n_; * calculate %age ;
			output; * output one row for each of the analyzed columns;
		end;
	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>Tue, 15 Sep 2015 13:24:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225551#M40505</guid>
      <dc:creator>ChrisWard</dc:creator>
      <dc:date>2015-09-15T13:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop for 2000 Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225634#M40524</link>
      <description>&lt;P&gt;Here's a worked example using both a proc transpose and the macro. The macro is inefficient but works quickly and across all types of variables, numeric/character. FYI You should show data in the text, rather than images, so we can copy and paste it into our code, it helps us to help you. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Generate sample data;
data have;
array q(20) q1-q20;
do id=1 to 100;
do i=1 to 20;
q(i)=floor(rand('uniform')*100+1);
x=rand('bernoulli', 0.1);
if x=1 then q(i)=.;
end;
output;
end;

drop i x;
run;

*check format;
proc print data=have(obs=5);
run;

*Flip dataset;
proc transpose data=have out=flipped(rename=(_name_=Question Col1=Value));
by id;
run;

*check format again;
proc print data=flipped(obs=10);
run;

*Count number missing using SQL step;
proc sql;
create table want as
select question, nmiss(value) as NMISS, count(question) as N,
	nmiss(value)/count(question) as PCT_MISS format=percent8.1
from flipped
group by question;
quit;

proc print data=want;
run;

*Sample output if used macro, make sure to run the macro first;
%sum_missing(work, have, want_macro);
proc print data=want_macro;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Sep 2015 15:53:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225634#M40524</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-09-15T15:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop for 2000 Columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225697#M40537</link>
      <description>&lt;P&gt;Thanks a lot. I was very important for me thanks again &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2015 20:05:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-for-2000-Columns/m-p/225697#M40537</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-09-15T20:05:51Z</dc:date>
    </item>
  </channel>
</rss>

