<?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: count occurrences of of variable values and assign label to in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299241#M63057</link>
    <description>&lt;P&gt;Why do you want a macro?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lables are attached to variables not values. You can use a format togehter with an output-procedure to mark counts below a threshold.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=sashelp.class;
   tables Age / out=work.forum;
run;

%let threshold = 2;

proc format;
   value AgeCountMarker
      LOW - &amp;amp;threshold = 'yellow'
      %eval(&amp;amp;threshold + 1) - HIGH = 'lightgreen'
   ;
run;

proc print data=work.forum;
   var Age;
   var Count / style(column)={background=AgeCountMarker.};
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 19 Sep 2016 11:30:21 GMT</pubDate>
    <dc:creator>error_prone</dc:creator>
    <dc:date>2016-09-19T11:30:21Z</dc:date>
    <item>
      <title>occurrences of of column values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299239#M63055</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello am trying to write a code to see if the column column value counts are&amp;nbsp;below a user-defined value then the value is replaced with a user defined value.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro Lfreq(indsn=,variable=);&lt;/P&gt;
&lt;P&gt;proc freq data = &amp;amp;indsn;&lt;BR /&gt;tables &amp;amp;variable;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%mend;&lt;BR /&gt;%Lfreq(indsn=myfile.freq2,variable=name);&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2016 14:03:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299239#M63055</guid>
      <dc:creator>RTelang</dc:creator>
      <dc:date>2016-09-21T14:03:25Z</dc:date>
    </item>
    <item>
      <title>Re: count occurrences of of variable values and assign label to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299240#M63056</link>
      <description>&lt;P&gt;What are you trying to replace? &amp;nbsp;Replace the count that prints in the table? &amp;nbsp;Or create a data set with the original variable being replaced?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 11:29:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299240#M63056</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-19T11:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: count occurrences of of variable values and assign label to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299241#M63057</link>
      <description>&lt;P&gt;Why do you want a macro?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lables are attached to variables not values. You can use a format togehter with an output-procedure to mark counts below a threshold.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=sashelp.class;
   tables Age / out=work.forum;
run;

%let threshold = 2;

proc format;
   value AgeCountMarker
      LOW - &amp;amp;threshold = 'yellow'
      %eval(&amp;amp;threshold + 1) - HIGH = 'lightgreen'
   ;
run;

proc print data=work.forum;
   var Age;
   var Count / style(column)={background=AgeCountMarker.};
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 11:30:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299241#M63057</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2016-09-19T11:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: count occurrences of of variable values and assign label to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299245#M63060</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt; i want to replace the value.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2016 13:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299245#M63060</guid>
      <dc:creator>RTelang</dc:creator>
      <dc:date>2016-09-21T13:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: count occurrences of of variable values and assign label to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299246#M63061</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/43025"&gt;@error_prone﻿&lt;/a&gt;&amp;nbsp;want &amp;nbsp;to check the occurrences of column variable values.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2016 14:04:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299246#M63061</guid>
      <dc:creator>RTelang</dc:creator>
      <dc:date>2016-09-21T14:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: count occurrences of of variable values and assign label to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299302#M63079</link>
      <description>&lt;P&gt;This doesn't show me what the outcome should be.&amp;nbsp; You will need to provide an example of the results that you want.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 14:50:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299302#M63079</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-19T14:50:52Z</dc:date>
    </item>
    <item>
      <title>Re: count occurrences of of variable values and assign label to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299308#M63081</link>
      <description>&lt;P&gt;Show some input data and expected results.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 14:59:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299308#M63081</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-09-19T14:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: count occurrences of of variable values and assign label to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299323#M63085</link>
      <description />
      <pubDate>Wed, 21 Sep 2016 07:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299323#M63085</guid>
      <dc:creator>RTelang</dc:creator>
      <dc:date>2016-09-21T07:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: count occurrences of of variable values and assign label to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299329#M63087</link>
      <description>&lt;P&gt;OK, that result is possible.&amp;nbsp; It may cause some confusion later, after your values have been replaced.&amp;nbsp; But it is possible.&amp;nbsp; This example assumes you are dealing with a character variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro change_value (indsn=, variable=, outdsn=, label=, threshold=);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; proc sort data=&amp;amp;indsn;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by &amp;amp;variable;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; proc freq data=&amp;amp;indsn;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tables &amp;amp;variable / noprint missing out=counts (keep=&amp;amp;variable count);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; data &amp;amp;outdsn;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; merge &amp;amp;indsn counts;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by &amp;amp;variable;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if count &amp;lt;= &amp;amp;threshold then &amp;amp;variable="&amp;amp;label";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop count;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;
&lt;P&gt;%mend change_value;&lt;/P&gt;
&lt;P&gt;%change_value (indsn=have, variable=name, outdsn=want, label=PQ, threshold=2)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's untested, but should be OK.&amp;nbsp; Give it a shot we'll find out.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 16:05:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299329#M63087</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-19T16:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: count occurrences of of variable values and assign label to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299431#M63149</link>
      <description>&lt;PRE&gt;
data test;
input name$10.;
retain dummy ' ';
cards;
lily
lily
lily
kate
kate
sam
sam
sam
;
run;

proc sql;
create table want(drop=dummy) as
select *,case when(count(*) gt 2) then 'PQ' else name end as want length=40
 from test
  group by name;
quit;


&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Sep 2016 03:04:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/occurrences-of-of-column-values/m-p/299431#M63149</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-09-20T03:04:15Z</dc:date>
    </item>
  </channel>
</rss>

