<?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 define the variable in general using base sas ? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/how-to-define-the-variable-in-general-using-base-sas/m-p/60427#M17116</link>
    <description>Dear Art ,&lt;BR /&gt;
&lt;BR /&gt;
Can explain the query.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Arpit</description>
    <pubDate>Sun, 09 Jan 2011 03:20:28 GMT</pubDate>
    <dc:creator>arpit</dc:creator>
    <dc:date>2011-01-09T03:20:28Z</dc:date>
    <item>
      <title>how to define the variable in general using base sas ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-define-the-variable-in-general-using-base-sas/m-p/60425#M17114</link>
      <description>define new variable B requiring that  the top 2 frequent values for variable1 to what they used be, the others are defined as OTHER.( Suppose A,B are the two, then variableB=A if variable B=A)  Since as more observations will be added soon, we do not know which two values for variable1 will be the most frequent; therefore, we need a general defined method with base SAS.&lt;BR /&gt;
ID	Loss	Variable1&lt;BR /&gt;
1	1000	A&lt;BR /&gt;
2	2000	A&lt;BR /&gt;
3	300	        B&lt;BR /&gt;
4	40000	C&lt;BR /&gt;
5	2300	E&lt;BR /&gt;
....&lt;BR /&gt;
Anyone can help me? Thanks.</description>
      <pubDate>Fri, 07 Jan 2011 20:29:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-define-the-variable-in-general-using-base-sas/m-p/60425#M17114</guid>
      <dc:creator>lucky66</dc:creator>
      <dc:date>2011-01-07T20:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to define the variable in general using base sas ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-define-the-variable-in-general-using-base-sas/m-p/60426#M17115</link>
      <description>While I haven't done a lot with views (shame on me), I would think that you could submit a small proc sql program that created a view containing the specifics that you outlined.  That way, any time you called the file, it would have the most recent top two values.&lt;BR /&gt;
&lt;BR /&gt;
Art</description>
      <pubDate>Sat, 08 Jan 2011 00:56:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-define-the-variable-in-general-using-base-sas/m-p/60426#M17115</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-01-08T00:56:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to define the variable in general using base sas ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-define-the-variable-in-general-using-base-sas/m-p/60427#M17116</link>
      <description>Dear Art ,&lt;BR /&gt;
&lt;BR /&gt;
Can explain the query.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Arpit</description>
      <pubDate>Sun, 09 Jan 2011 03:20:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-define-the-variable-in-general-using-base-sas/m-p/60427#M17116</guid>
      <dc:creator>arpit</dc:creator>
      <dc:date>2011-01-09T03:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to define the variable in general using base sas ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-define-the-variable-in-general-using-base-sas/m-p/60428#M17117</link>
      <description>I also want to know. Thanks.</description>
      <pubDate>Sun, 09 Jan 2011 20:13:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-define-the-variable-in-general-using-base-sas/m-p/60428#M17117</guid>
      <dc:creator>lucky66</dc:creator>
      <dc:date>2011-01-09T20:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: how to define the variable in general using base sas ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-define-the-variable-in-general-using-base-sas/m-p/60429#M17118</link>
      <description>it looks to me like the PROC MEANS feature IDGROUP should be able to easily deliver the "top-two" most conveniently. However, leaving that sophistication to those specialists, here is a bit of basic sql;&lt;BR /&gt;
First load your data[pre]data your.data;&lt;BR /&gt;
input iD Loss Variable1 $ ; list;cards;&lt;BR /&gt;
1 1000 A&lt;BR /&gt;
2 2000 A&lt;BR /&gt;
3 300 B&lt;BR /&gt;
4 40000 C&lt;BR /&gt;
5 2300 E&lt;BR /&gt;
;[/pre]then identify the most frequent cases (I want to put the top two variable1 values into macro variables, so am using SQL[pre]proc sql noprint ;&lt;BR /&gt;
select variable1 into :v1-:v9999&lt;BR /&gt;
from ( select variable1, count(*) as cases from your.data     &lt;BR /&gt;
     group by variable1&lt;BR /&gt;
     )&lt;BR /&gt;
order by cases descending&lt;BR /&gt;
;&lt;BR /&gt;
quit ;[/pre]* then a character informat which allows use of _SAME_, leaving top-two unchanged;[pre]proc format ;&lt;BR /&gt;
 invalue $top_two "&amp;amp;v1", "&amp;amp;v2" = _same_ &lt;BR /&gt;
                         other = 'OTHER' ;&lt;BR /&gt;
run;[/pre]* then use this informat to derive the new column in a data step view;[pre]&lt;BR /&gt;
data v /view=v ;&lt;BR /&gt;
set your.data ;&lt;BR /&gt;
simpler = input( variable1, $top_two. ) ;&lt;BR /&gt;
run ;[/pre] * now run a print to show the results;[pre]option nocenter ls=64 ; &lt;BR /&gt;
proc print ;&lt;BR /&gt;
title 'informat applied';&lt;BR /&gt;
run;&lt;BR /&gt;
informat applied             &lt;BR /&gt;
 &lt;BR /&gt;
     Obs    iD     Loss    Variable1    simpler&lt;BR /&gt;
&lt;BR /&gt;
       1     1     1000        A         A&lt;BR /&gt;
       2     2     2000        A         A&lt;BR /&gt;
       3     3      300        B         OTHER&lt;BR /&gt;
       4     4    40000        C         C&lt;BR /&gt;
       5     5     2300        E         OTHER[/pre]*Of course, it might be simpler just to create a top_two format for use in analysing the data - without creating the view or re-writing the data!&lt;BR /&gt;
Adapt the proc format only slightly ;[pre]proc format ;&lt;BR /&gt;
   value $top_two "&amp;amp;v1" = "&amp;amp;v1"  &lt;BR /&gt;
                  "&amp;amp;v2" = "&amp;amp;v2" /* unable to use _SAME_ in value statement*/ &lt;BR /&gt;
                  other = 'OTHER' ;&lt;BR /&gt;
run;[/pre]* now using the top_two format in proc means and print to show results;[pre]proc means data= your.data nway ;&lt;BR /&gt;
   format variable1 $top_two. ;&lt;BR /&gt;
   class  variable1 ;&lt;BR /&gt;
   var    loss ;&lt;BR /&gt;
   output sum= out= summary ;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print ;&lt;BR /&gt;
title 'format summary demo';&lt;BR /&gt;
run; &lt;BR /&gt;
format summary demo                         &lt;BR /&gt;
&lt;BR /&gt;
Obs    Variable1    _TYPE_    _FREQ_     Loss&lt;BR /&gt;
&lt;BR /&gt;
 1       A             1         2       3000&lt;BR /&gt;
 2       OTHER         1         2       2600&lt;BR /&gt;
 3       C             1         1      40000[/pre] Think I prefer the format route.  &lt;BR /&gt;
peterC</description>
      <pubDate>Mon, 10 Jan 2011 12:19:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-define-the-variable-in-general-using-base-sas/m-p/60429#M17118</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-01-10T12:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to define the variable in general using base sas ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-define-the-variable-in-general-using-base-sas/m-p/60430#M17119</link>
      <description>Peter, thank you so much.</description>
      <pubDate>Tue, 25 Jan 2011 00:59:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-define-the-variable-in-general-using-base-sas/m-p/60430#M17119</guid>
      <dc:creator>lucky66</dc:creator>
      <dc:date>2011-01-25T00:59:56Z</dc:date>
    </item>
  </channel>
</rss>

