<?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: How to tell what variable (column name) the data step is currently on in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/562337#M10728</link>
    <description>&lt;P&gt;By reading ballardw's response I realized that n(of) did not work for me because the data in the variables are character not numeric.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 29 May 2019 16:23:58 GMT</pubDate>
    <dc:creator>lberger</dc:creator>
    <dc:date>2019-05-29T16:23:58Z</dc:date>
    <item>
      <title>How to tell what variable (column name) the data step is currently on</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/562010#M10678</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;New SAS user. Using SAS University through virtual box on win 10. Comfortable coding but getting use to SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a group of variables (column names) that share a prefix such as: blah1 through blah99.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My goal is to count the number of non missing values of each variable and create a new column with that count,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to do something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;IF currentVar contains 'blah' and not missing(currentVar) then

do;

...

end;&lt;/PRE&gt;&lt;P&gt;Or is my only option a Do loop with an Array? If so, I will post the issue I am having with my loop later.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or should I create a new table with just those variables and count them?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Lon&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 16:24:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/562010#M10678</guid>
      <dc:creator>lberger</dc:creator>
      <dc:date>2019-05-28T16:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to tell what variable (column name) the data step is currently on</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/562017#M10680</link>
      <description>&lt;P&gt;Actually, creating a table with just those variables won't solve the issue either. So I take that back.&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 16:52:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/562017#M10680</guid>
      <dc:creator>lberger</dc:creator>
      <dc:date>2019-05-28T16:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to tell what variable (column name) the data step is currently on</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/562018#M10681</link>
      <description>&lt;P&gt;Just use the N function with a variable list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;count = n(of blah1-blah99);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you don't know the exact variable names but you want all of those that start the a prefix then use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;count = n(of blah:);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 May 2019 17:05:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/562018#M10681</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-28T17:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to tell what variable (column name) the data step is currently on</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/562021#M10684</link>
      <description>&lt;P&gt;You might want to provide some example data and the desired result for that example. One interpretation&amp;nbsp;for "count the number of non missing values of each variable" would be across observations which would mean getting your count and then merging the summary data back.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, are all of the variables numeric? That would make the count in any form easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;'s solution will count non-missing numeric variables per observation (or record / row if you prefer)&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 17:14:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/562021#M10684</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-28T17:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to tell what variable (column name) the data step is currently on</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/562029#M10688</link>
      <description>&lt;P&gt;Sounds like you want a missing report. I would recommend a different approach entirely - use PROC FREQ to summarize data for each variable into missing and non missing. This is a fully worked example that generates a 'pretty table'.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest running it twice, once as is to see the results and if it's what you want. If so, then change the parameters (in red) to your input data set and output data set and run everything below that line again to get the desired results for your table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data class;
    set sashelp.class;

    if age=14 then
        call missing(height, weight, sex);

    if name='Alfred' then
        call missing(sex, age, height);
    label age="Fancy Age Label";
run;

*set input data set name;
&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;%let INPUT_DSN = class;
%let OUTPUT_DSN = want;&lt;/STRONG&gt;&lt;/FONT&gt;
*create format for missing;

proc format;
    value $ missfmt ' '="Missing" other="Not Missing";
    value nmissfmt .="Missing" other="Not Missing";
run;

*Proc freq to count missing/non missing;
ods select none;
*turns off the output so the results do not get too messy;
ods table onewayfreqs=temp;

proc freq data=&amp;amp;INPUT_DSN.;
    table _all_ / missing;
    format _numeric_ nmissfmt. _character_ $missfmt.;
run;

ods select all;
*Format output;

data long;
    length variable $32. variable_value $50.;
    set temp;
    Variable=scan(table, 2);
    Variable_Value=strip(trim(vvaluex(variable)));
    presentation=catt(frequency, " (", trim(put(percent/100, percent7.1)), ")");
    keep variable variable_value frequency percent cum: presentation;
    label variable='Variable' variable_value='Variable Value';
run;

proc sort data=long;
    by variable;
run;

*make it a wide data set for presentation, with values as N (Percent);

proc transpose data=long out=wide_presentation (drop=_name_);
    by variable;
    id variable_value;
    var presentation;
run;

*transpose only N;

proc transpose data=long out=wide_N prefix=N_;
    by variable;
    id variable_value;
    var frequency;
run;

*transpose only percents;

proc transpose data=long out=wide_PCT prefix=PCT_;
    by variable;
    id variable_value;
    var percent;
run;

*final output file;

data &amp;amp;Output_DSN.;
    merge wide_N wide_PCT wide_presentation;
    by variable;
    drop _name_;
    label N_Missing='# Missing' N_Not_Missing='# Not Missing' 
        PCT_Missing='% Missing' N_Not_Missing='% Not Missing' Missing='Missing' 
        Not_missing='Not Missing';
run;

title "Missing Report of &amp;amp;INPUT_DSN.";

proc print data=&amp;amp;output_dsn. noobs label;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 May 2019 17:51:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/562029#M10688</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-28T17:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to tell what variable (column name) the data step is currently on</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/562329#M10724</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For some reason I was unable to get either to work. I kept getting zero. I will keep trying because it must be an issue on my end. That seems like a logical solution. It is strange, with how robust SAS is, that there is no way to get the current variable (column name) in a data step as it loops.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ended up going with a do loop for now. I can then just get a mean of the new column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;count=0;
array diagGrp(*) DIAG1-DIAG63;
do i=1 to 63;
	if not missing(diagGrp(i)) then
	do;
		count+1;
	end;
end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Lon&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 16:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/562329#M10724</guid>
      <dc:creator>lberger</dc:creator>
      <dc:date>2019-05-29T16:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to tell what variable (column name) the data step is currently on</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/562333#M10727</link>
      <description>&lt;P&gt;Hello ballardw,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to count non missing values whether or not they are numeric or character.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;B1&amp;nbsp; B2&amp;nbsp; B3&amp;nbsp; B4&amp;nbsp; B5&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;aa&amp;nbsp; &amp;nbsp;bb&amp;nbsp; aa&amp;nbsp; &amp;nbsp;dd&amp;nbsp; &amp;nbsp;cc&lt;/P&gt;&lt;P&gt;cc&amp;nbsp; &amp;nbsp;aa&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cc&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So this would result in 5 for the first row and 3 for the second row. I ended up with a do loop:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;count=0;
array diagGrp(*) DIAG1-DIAG63;
do i=1 to 63;
	if not missing(diagGrp(i)) then
	do;
		count+1;
	end;
end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Lon&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 16:19:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/562333#M10727</guid>
      <dc:creator>lberger</dc:creator>
      <dc:date>2019-05-29T16:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to tell what variable (column name) the data step is currently on</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/562337#M10728</link>
      <description>&lt;P&gt;By reading ballardw's response I realized that n(of) did not work for me because the data in the variables are character not numeric.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 16:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/562337#M10728</guid>
      <dc:creator>lberger</dc:creator>
      <dc:date>2019-05-29T16:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to tell what variable (column name) the data step is currently on</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/562342#M10730</link>
      <description>&lt;P&gt;Hello Reeza,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I admire the work done here. I only need to create a column that contains the number of non missing values so I can get a mean of those counts. I will note this for future use. I ended up using a do loop as posted in the other responses.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Lon&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 16:29:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/562342#M10730</guid>
      <dc:creator>lberger</dc:creator>
      <dc:date>2019-05-29T16:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to tell what variable (column name) the data step is currently on</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/563406#M10881</link>
      <description>&lt;P&gt;It appears there is no function or variable in SAS to tell which column is currently being read in the data step. You can tell the row number with &lt;FONT color="#0000FF"&gt;_N_&lt;/FONT&gt; but not the column.&lt;FONT color="#0000FF"&gt; n(of )&lt;/FONT&gt; as stated by Tom in this thread is nice, but seems to have no character equal. Bizarre. So, if you know what the names of the columns are you can count observations with this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;count=0;
array diagGrp(*) DIAG1-DIAG63;
do i=1 to 63;
	if not missing(diagGrp(i)) then
	do;
		count+1;
	end;
end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;No fancy code. Just a basic loop that does nothing other than what is stated.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2019 22:32:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/563406#M10881</guid>
      <dc:creator>lberger</dc:creator>
      <dc:date>2019-06-03T22:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to tell what variable (column name) the data step is currently on</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/563425#M10882</link>
      <description>&lt;P&gt;You don't need a loop for that then, use the CMISS function to count missing records. Use DIM to get the dimension/number of variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
array diagGrp(*) DIAG1-DIAG63;

non_missing = dim(diagGrp) - cmiss(of diagGrp(*));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/273116"&gt;@lberger&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello Reeza,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I admire the work done here. I only need to create a column that contains the number of non missing values so I can get a mean of those counts. I will note this for future use. I ended up using a do loop as posted in the other responses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;Lon&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 03:18:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-tell-what-variable-column-name-the-data-step-is-currently/m-p/563425#M10882</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-04T03:18:44Z</dc:date>
    </item>
  </channel>
</rss>

