<?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: Create a new variable based on a frequency in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable-based-on-a-frequency/m-p/585844#M14388</link>
    <description>&lt;P&gt;Try something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA table1;
INPUT AGE$;
CARDS;
053
047
081
029
029
029
029
053
012
;
RUN;
proc sql;
   select count(*) into :age29
   from table where age eq '029';
quit;
DATA table2;
SET table1;
NEWVAR = &amp;amp;age29.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 03 Sep 2019 14:36:09 GMT</pubDate>
    <dc:creator>JosvanderVelden</dc:creator>
    <dc:date>2019-09-03T14:36:09Z</dc:date>
    <item>
      <title>Create a new variable based on a frequency</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable-based-on-a-frequency/m-p/585830#M14384</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have my dataset in SAS as follows&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA table;
INPUT AGE$;
CARDS;
053
047
081
029
029
029
029
053
012
;
RUN;&lt;/PRE&gt;&lt;P&gt;As result&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AGE.png" style="width: 94px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32180i0E71E2365BFB6CE4/image-size/large?v=v2&amp;amp;px=999" role="button" title="AGE.png" alt="AGE.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is to create a new variable in a column based on the frequency value of age '029', so that the new column has the value '4' in each row. I have tried to use the COUNT function, but it only gives me '1' in the row where '029' is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA table2;
SET table1;
NEWVAR = count(AGE,'029');
run;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="newvar.png" style="width: 209px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32181i64030D8C080CB1B3/image-size/large?v=v2&amp;amp;px=999" role="button" title="newvar.png" alt="newvar.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I do not want this. In Excel is easy to do, let me illustrate my desired result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="excel.png" style="width: 161px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32183i3FD53688E3C5C5AB/image-size/large?v=v2&amp;amp;px=999" role="button" title="excel.png" alt="excel.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All I used in excel was&amp;nbsp;&lt;SPAN&gt;=COUNTIF&lt;/SPAN&gt;($A$2:$A$10,29). How to do the same thing in SAS?&lt;/P&gt;&lt;P&gt;I will really appreciate your answer.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2019 14:07:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable-based-on-a-frequency/m-p/585830#M14384</guid>
      <dc:creator>yascm</dc:creator>
      <dc:date>2019-09-03T14:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable based on a frequency</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable-based-on-a-frequency/m-p/585836#M14386</link>
      <description>&lt;P&gt;Welcome to the SAS Community &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one way using the data step&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA table;
INPUT AGE$;
CARDS;
053
047
081
029
029
029
029
053
012
;
RUN;

data want;
	do until (lr1);
		set table end=lr1;
		if age='029' then newvar+1;
	end;
	do until (lr2);
		set table end=lr2;
		output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Sep 2019 14:29:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable-based-on-a-frequency/m-p/585836#M14386</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-03T14:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable based on a frequency</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable-based-on-a-frequency/m-p/585842#M14387</link>
      <description>&lt;P&gt;Here is an SQL approach&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table want as
	select Age, sum(age='029') as newvar
	from table;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Sep 2019 14:33:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable-based-on-a-frequency/m-p/585842#M14387</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-03T14:33:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable based on a frequency</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable-based-on-a-frequency/m-p/585844#M14388</link>
      <description>&lt;P&gt;Try something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA table1;
INPUT AGE$;
CARDS;
053
047
081
029
029
029
029
053
012
;
RUN;
proc sql;
   select count(*) into :age29
   from table where age eq '029';
quit;
DATA table2;
SET table1;
NEWVAR = &amp;amp;age29.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Sep 2019 14:36:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable-based-on-a-frequency/m-p/585844#M14388</guid>
      <dc:creator>JosvanderVelden</dc:creator>
      <dc:date>2019-09-03T14:36:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable based on a frequency</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable-based-on-a-frequency/m-p/585845#M14389</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select count(age) into :newvar
  from table
 where age eq "029";
quit;
data want;
 set table;
    newvar=&amp;amp;newvar;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Sep 2019 14:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable-based-on-a-frequency/m-p/585845#M14389</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2019-09-03T14:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable based on a frequency</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable-based-on-a-frequency/m-p/585857#M14390</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA table;
INPUT AGE$;
CARDS;
053
047
081
029
029
029
029
053
012
;
RUN;

proc sql;
create table want(drop=m) as
select age,monotonic() as m, count
from table,(select count(age) as count from table where age='029') 
order by m;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Sep 2019 15:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-a-new-variable-based-on-a-frequency/m-p/585857#M14390</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-03T15:20:03Z</dc:date>
    </item>
  </channel>
</rss>

