COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Ranking by State

• Email
• Follow

```I need help figuring out how to rank my results by state.For each
color what is the rank(based on SumVal)  for all states .. I have this
SAS dataset

State  sumval     Color
AK      10           Red
AK      12           Blue
AK      7              Green
AZ       3             Yellow
AZ      5              Red
AZ     20             Blue
NY     2               Green

etc...
The output will list all states with Rankings  by Color :

Red
State    SumVal     Rank
AK       10                1
AZ         5                2
NY        0                 .

Blue
State    SumVal     Rank
AK       12                2
AZ         20               1
NY        0                 .

Green
State    SumVal     Rank
AK       0               .
AZ         3               1
NY        0                .

Green
State    SumVal     Rank
AK       7                1
AZ         0               .
NY        2                2

So one report for each of Colors (I have 50 or so)
and I need to list all 50 states even if the value is 0, and if the
value is zero that the rank should be missing.
Thank you
```
 0
Reply sdlentertd (65) 3/2/2010 11:14:10 PM

See related articles to this posting

```On Mar 2, 4:14=A0pm, Sdlentertd <sdlente...@gmail.com> wrote:
> I need help figuring out how to rank my results by state.For each
> color what is the rank(based on SumVal) =A0for all states .. I have this
> SAS dataset
>
> State =A0sumval =A0 =A0 Color
> AK =A0 =A0 =A010 =A0 =A0 =A0 =A0 =A0 Red
> AK =A0 =A0 =A012 =A0 =A0 =A0 =A0 =A0 Blue
> AK =A0 =A0 =A07 =A0 =A0 =A0 =A0 =A0 =A0 =A0Green
> AZ =A0 =A0 =A0 3 =A0 =A0 =A0 =A0 =A0 =A0 Yellow
> AZ =A0 =A0 =A05 =A0 =A0 =A0 =A0 =A0 =A0 =A0Red
> AZ =A0 =A0 20 =A0 =A0 =A0 =A0 =A0 =A0 Blue
> NY =A0 =A0 2 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Green
>
> etc...
> The output will list all states with Rankings =A0by Color :
>
> Red
> State =A0 =A0SumVal =A0 =A0 Rank
> AK =A0 =A0 =A0 10 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A01
> AZ =A0 =A0 =A0 =A0 5 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A02
> NY =A0 =A0 =A0 =A00 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .
>
> Blue
> State =A0 =A0SumVal =A0 =A0 Rank
> AK =A0 =A0 =A0 12 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A02
> AZ =A0 =A0 =A0 =A0 20 =A0 =A0 =A0 =A0 =A0 =A0 =A0 1
> NY =A0 =A0 =A0 =A00 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .
>
> Green
> State =A0 =A0SumVal =A0 =A0 Rank
> AK =A0 =A0 =A0 0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .
> AZ =A0 =A0 =A0 =A0 3 =A0 =A0 =A0 =A0 =A0 =A0 =A0 1
> NY =A0 =A0 =A0 =A00 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0.
>
> Green
> State =A0 =A0SumVal =A0 =A0 Rank
> AK =A0 =A0 =A0 7 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A01
> AZ =A0 =A0 =A0 =A0 0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .
> NY =A0 =A0 =A0 =A02 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A02
>
> So one report for each of Colors (I have 50 or so)
> and I need to list all 50 states even if the value is 0, and if the
> value is zero that the rank should be missing.
> Thank you

I came up with this code, but it doesn't list all states, only
populated ones.

proc rank data=3Dhave out=3Dnew descending ties =3D low ;
by color;

var SumVal    ;

run;
```
 0

```I really should just wait until data_null_ shows us the direct way to
do what you want but, in case you need it right away, I think that the

data have;
input State \$  sumval     Color \$;
cards;
AK      10           Red
AK      12           Blue
AK      7              Green
AZ       3             Yellow
AZ      5              Red
AZ     20             Blue
NY     2               Green
;

proc sort data=have;
by color state;
run;

proc sql noprint;
create table need as
select unique l.state,
r.color
from have as l, have as r
order by color,state;
quit;

data need;
merge have need;
by color state;
if missing(sumval) then sumval=0;
run;

proc sort data=need;
by color;
run;

proc rank data=need descending out=want;
by color;
var sumval;
ranks rank;
run;

proc sort data=want;
by color rank state;
run;

data want;
set want;
if sumval eq 0 then call missing(rank);
run;

proc print data=want;
run;

HTH,
Art
------------
On Mar 2, 6:41 pm, Sdlentertd <sdlente...@gmail.com> wrote:
> On Mar 2, 4:14 pm, Sdlentertd <sdlente...@gmail.com> wrote:
>
>
>
>
>
> > I need help figuring out how to rank my results by state.For each
> > color what is the rank(based on SumVal)  for all states .. I have this
> > SAS dataset
>
> > State  sumval     Color
> > AK      10           Red
> > AK      12           Blue
> > AK      7              Green
> > AZ       3             Yellow
> > AZ      5              Red
> > AZ     20             Blue
> > NY     2               Green
>
> > etc...
> > The output will list all states with Rankings  by Color :
>
> > Red
> > State    SumVal     Rank
> > AK       10                1
> > AZ         5                2
> > NY        0                 .
>
> > Blue
> > State    SumVal     Rank
> > AK       12                2
> > AZ         20               1
> > NY        0                 .
>
> > Green
> > State    SumVal     Rank
> > AK       0               .
> > AZ         3               1
> > NY        0                .
>
> > Green
> > State    SumVal     Rank
> > AK       7                1
> > AZ         0               .
> > NY        2                2
>
> > So one report for each of Colors (I have 50 or so)
> > and I need to list all 50 states even if the value is 0, and if the
> > value is zero that the rank should be missing.
> > Thank you
>
> I came up with this code, but it doesn't list all states, only
> populated ones.
>
> proc rank data=have out=new descending ties = low ;
>    by color;
>
>    var SumVal    ;
>
> run;- Hide quoted text -
>
> - Show quoted text -
```
 0

```hi ... here's another idea ...

data x;
input state : \$2.  sumval color : \$6.;
datalines;
AK      10           Red
AK      12           Blue
AK      7              Green
AZ       3             Yellow
AZ      5              Red
AZ     20             Blue
NY     2               Green
;
run;

proc summary data=x nway completetypes;
class color state;
var sumval;
output out=y (drop=_:) sum=;
run;

proc rank data=y out=y;
var sumval;
by color;
ranks rank;
run;

proc print data=y noobs;
by color;
run;

output ...

COLOR=Blue
state    sumval    rank
AK        12        1
AZ        20        2
NY         .        .

COLOR=Green
state    sumval    rank
AK         7        2
AZ         .        .
NY         2        1

COLOR=Red
state    sumval    rank
AK        10        2
AZ         5        1
NY         .        .

COLOR=Yellow
state    sumval    rank
AK         .        .
AZ         3        1
NY         .        .

--
Mike Zdeb
U@Albany School of Public Health
One University Place
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475

> I really should just wait until data_null_ shows us the direct way to
> do what you want but, in case you need it right away, I think that the
>
> data have;
>   input State \$  sumval     Color \$;
>   cards;
> AK      10           Red
> AK      12           Blue
> AK      7              Green
> AZ       3             Yellow
> AZ      5              Red
> AZ     20             Blue
> NY     2               Green
> ;
>
> proc sort data=have;
>   by color state;
> run;
>
> proc sql noprint;
>   create table need as
>     select unique l.state,
>                   r.color
>       from have as l, have as r
>         order by color,state;
> quit;
>
> data need;
>   merge have need;
>   by color state;
>   if missing(sumval) then sumval=0;
> run;
>
> proc sort data=need;
>   by color;
> run;
>
> proc rank data=need descending out=want;
>   by color;
>   var sumval;
>   ranks rank;
> run;
>
> proc sort data=want;
>   by color rank state;
> run;
>
> data want;
>   set want;
>   if sumval eq 0 then call missing(rank);
> run;
>
> proc print data=want;
> run;
>
> HTH,
> Art
> ------------
> On Mar 2, 6:41 pm, Sdlentertd <sdlente...@gmail.com> wrote:
>> On Mar 2, 4:14 pm, Sdlentertd <sdlente...@gmail.com> wrote:
>>
>>
>>
>>
>>
>> > I need help figuring out how to rank my results by state.For each
>> > color what is the rank(based on SumVal)  for all states .. I have this
>> > SAS dataset
>>
>> > State  sumval     Color
>> > AK      10           Red
>> > AK      12           Blue
>> > AK      7              Green
>> > AZ       3             Yellow
>> > AZ      5              Red
>> > AZ     20             Blue
>> > NY     2               Green
>>
>> > etc...
>> > The output will list all states with Rankings  by Color :
>>
>> > Red
>> > State    SumVal     Rank
>> > AK       10                1
>> > AZ         5                2
>> > NY        0                 .
>>
>> > Blue
>> > State    SumVal     Rank
>> > AK       12                2
>> > AZ         20               1
>> > NY        0                 .
>>
>> > Green
>> > State    SumVal     Rank
>> > AK       0               .
>> > AZ         3               1
>> > NY        0                .
>>
>> > Green
>> > State    SumVal     Rank
>> > AK       7                1
>> > AZ         0               .
>> > NY        2                2
>>
>> > So one report for each of Colors (I have 50 or so)
>> > and I need to list all 50 states even if the value is 0, and if the
>> > value is zero that the rank should be missing.
>> > Thank you
>>
>> I came up with this code, but it doesn't list all states, only
>> populated ones.
>>
>> proc rank data=have out=new descending ties = low ;
>>    by color;
>>
>>    var SumVal    ;
>>
>> run;- Hide quoted text -
>>
>> - Show quoted text -
>
```
 0

```hi ... didn't notice descending order of rank ...

just use stuff in last posting below and add descending ...

proc rank data=y out=y descending;
var sumval;
by color;
ranks rank;
run;

ps  if you really want those missing values of sumval to be 0
use a  data step after PROC RANK ...

proc summary data=x nway completetypes;
class color state;
var sumval;
output out=y (drop=_:) sum=;
run;

proc rank data=y out=y descending;
var sumval;
by color;
ranks rank;
run;

data y;
set y;
sumval = sum(sumval,0);
run;

--
Mike Zdeb
U@Albany School of Public Health
One University Place
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475

> hi ... here's another idea ...
>
> data x;
> input state : \$2.  sumval color : \$6.;
> datalines;
> AK      10           Red
> AK      12           Blue
> AK      7              Green
> AZ       3             Yellow
> AZ      5              Red
> AZ     20             Blue
> NY     2               Green
> ;
> run;
>
> proc summary data=x nway completetypes;
> class color state;
> var sumval;
> output out=y (drop=_:) sum=;
> run;
>
> proc rank data=y out=y;
> var sumval;
> by color;
> ranks rank;
> run;
>
> proc print data=y noobs;
> by color;
> run;
>
> output ...
>
> COLOR=Blue
> state    sumval    rank
>  AK        12        1
>  AZ        20        2
>  NY         .        .
>
>
> COLOR=Green
> state    sumval    rank
>  AK         7        2
>  AZ         .        .
>  NY         2        1
>
>
> COLOR=Red
> state    sumval    rank
>  AK        10        2
>  AZ         5        1
>  NY         .        .
>
>
> COLOR=Yellow
> state    sumval    rank
>  AK         .        .
>  AZ         3        1
>  NY         .        .
>
>
>
> --
> Mike Zdeb
> U@Albany School of Public Health
> One University Place
> Rensselaer, New York 12144-3456
> P/518-402-6479 F/630-604-1475
>
>> I really should just wait until data_null_ shows us the direct way to
>> do what you want but, in case you need it right away, I think that the
>>
>> data have;
>>   input State \$  sumval     Color \$;
>>   cards;
>> AK      10           Red
>> AK      12           Blue
>> AK      7              Green
>> AZ       3             Yellow
>> AZ      5              Red
>> AZ     20             Blue
>> NY     2               Green
>> ;
>>
>> proc sort data=have;
>>   by color state;
>> run;
>>
>> proc sql noprint;
>>   create table need as
>>     select unique l.state,
>>                   r.color
>>       from have as l, have as r
>>         order by color,state;
>> quit;
>>
>> data need;
>>   merge have need;
>>   by color state;
>>   if missing(sumval) then sumval=0;
>> run;
>>
>> proc sort data=need;
>>   by color;
>> run;
>>
>> proc rank data=need descending out=want;
>>   by color;
>>   var sumval;
>>   ranks rank;
>> run;
>>
>> proc sort data=want;
>>   by color rank state;
>> run;
>>
>> data want;
>>   set want;
>>   if sumval eq 0 then call missing(rank);
>> run;
>>
>> proc print data=want;
>> run;
>>
>> HTH,
>> Art
>> ------------
>> On Mar 2, 6:41 pm, Sdlentertd <sdlente...@gmail.com> wrote:
>>> On Mar 2, 4:14 pm, Sdlentertd <sdlente...@gmail.com> wrote:
>>>
>>>
>>>
>>>
>>>
>>> > I need help figuring out how to rank my results by state.For each
>>> > color what is the rank(based on SumVal)  for all states .. I have this
>>> > SAS dataset
>>>
>>> > State  sumval     Color
>>> > AK      10           Red
>>> > AK      12           Blue
>>> > AK      7              Green
>>> > AZ       3             Yellow
>>> > AZ      5              Red
>>> > AZ     20             Blue
>>> > NY     2               Green
>>>
>>> > etc...
>>> > The output will list all states with Rankings  by Color :
>>>
>>> > Red
>>> > State    SumVal     Rank
>>> > AK       10                1
>>> > AZ         5                2
>>> > NY        0                 .
>>>
>>> > Blue
>>> > State    SumVal     Rank
>>> > AK       12                2
>>> > AZ         20               1
>>> > NY        0                 .
>>>
>>> > Green
>>> > State    SumVal     Rank
>>> > AK       0               .
>>> > AZ         3               1
>>> > NY        0                .
>>>
>>> > Green
>>> > State    SumVal     Rank
>>> > AK       7                1
>>> > AZ         0               .
>>> > NY        2                2
>>>
>>> > So one report for each of Colors (I have 50 or so)
>>> > and I need to list all 50 states even if the value is 0, and if the
>>> > value is zero that the rank should be missing.
>>> > Thank you
>>>
>>> I came up with this code, but it doesn't list all states, only
>>> populated ones.
>>>
>>> proc rank data=have out=new descending ties = low ;
>>>    by color;
>>>
>>>    var SumVal    ;
>>>
>>> run;- Hide quoted text -
>>>
>>> - Show quoted text -
>>
>
```
 0
Reply msz03 (782) 3/3/2010 1:54:45 AM

```I was late to read this thread. Mike Zdeb has given a solution based on proc
summary and proc rank. I was thinking to use hash objects. It looked
difficult at first to incorporate all the needs of the OP in a hash
solution. It is not.

data have;
input state : \$2.  sumval color : \$6.;
datalines;
AK  10 Red
AK  12 Blue
AK   7 Green
AZ   3 Yellow
AZ   5 Red
AZ  20 Blue
NY   2 Green
;
run;

It needs a  presorted data set to get the ranks. A hash table is stored
based on the keys of color and state. Another hash table is built to save
only the unique colors to check the presence in the former hash table to add
missing values.

proc sort data = have;
by color descending sumval;
run;

data _null_;
if _n_ = 1 then do;
if 0 then set have;

declare hash h(ordered:'y');
h.definekey('color','state');
h.definedata('color','state','sumval','rank');
h.definedone();

declare hash s(ordered:'y');
s.definekey('st');
s.definedone();

do until(z);
do until(last.color);
set have(keep = state rename=(state = st)) end = z;
if s.check() ne 0 then s.add();
end;
end;

declare hiter hi('s');
end;

do until(last);
rank = 0;
do until(last.color);
set have end = last;
by color;
if h.find() ne 0 then rank + 1;
h.replace();
end;

** check all states are inserted;

do rc = hi.first() by 0 while(rc = 0);
if h.find(key:color,key:st) ne 0 then do;
state = st;
sumval = 0;
rank = .;
end;
rc = hi.next();
end;
end;
h.output(dataset:'need');
stop;
run;

proc print data = need noobs;
run;

The output of dataset:

color     state    sumval    rank

Blue       AK        12        2
Blue       AZ        20        1
Blue       NY         0        .
Green      AK         7        1
Green      AZ         0        .
Green      NY         2        2
Red        AK        10        1
Red        AZ         5        2
Red        NY         0        .
Yellow     AK         0        .
Yellow     AZ         3        1
Yellow     NY         0        .

Muthia Kachirayan

On Tue, Mar 2, 2010 at 7:14 PM, Sdlentertd <sdlentertd@gmail.com> wrote:

>  I need help figuring out how to rank my results by state.For each
> color what is the rank(based on SumVal)  for all states .. I have this
> SAS dataset
>
> State  sumval     Color
> AK      10           Red
> AK      12           Blue
> AK      7              Green
> AZ       3             Yellow
> AZ      5              Red
> AZ     20             Blue
> NY     2               Green
>
> etc...
> The output will list all states with Rankings  by Color :
>
> Red
> State    SumVal     Rank
> AK       10                1
> AZ         5                2
> NY        0                 .
>
> Blue
> State    SumVal     Rank
> AK       12                2
> AZ         20               1
> NY        0                 .
>
> Green
> State    SumVal     Rank
> AK       0               .
> AZ         3               1
> NY        0                .
>
> Green
> State    SumVal     Rank
> AK       7                1
> AZ         0               .
> NY        2                2
>
> So one report for each of Colors (I have 50 or so)
> and I need to list all 50 states even if the value is 0, and if the
> value is zero that the rank should be missing.
> Thank you
>
```
 0
Reply muthia.kachirayan (702) 3/4/2010 4:40:12 PM

```It is not unique colors but state.

On Thu, Mar 4, 2010 at 12:40 PM, Muthia Kachirayan <
muthia.kachirayan@gmail.com> wrote:

> I was late to read this thread. Mike Zdeb has given a solution based on
> proc summary and proc rank. I was thinking to use hash objects. It looked
> difficult at first to incorporate all the needs of the OP in a hash
> solution. It is not.
>
>
> data have;
>
> input state : \$2.  sumval color : \$6.;
> datalines;
> AK  10 Red
> AK  12 Blue
> AK   7 Green
> AZ   3 Yellow
> AZ   5 Red
> AZ  20 Blue
> NY   2 Green
> ;
> run;
>
> It needs a  presorted data set to get the ranks. A hash table is stored
> based on the keys of color and state. Another hash table is built to save
> only the unique colors to check the presence in the former hash table to add
> missing values.
>
>
> proc sort data = have;
> by color descending sumval;
> run;
>
> data _null_;
> if _n_ = 1 then do;
>
>    if 0 then set have;
>
>    declare hash h(ordered:'y');
>    h.definekey('color','state');
>    h.definedata('color','state','sumval','rank');
>    h.definedone();
>
>    declare hash s(ordered:'y');
>    s.definekey('st');
>    s.definedone();
>
>    do until(z);
>       do until(last.color);
>          set have(keep = state rename=(state = st)) end = z;
>          if s.check() ne 0 then s.add();
>       end;
>    end;
>
>    declare hiter hi('s');
> end;
>
> do until(last);
>    rank = 0;
>    do until(last.color);
>       set have end = last;
>       by color;
>       if h.find() ne 0 then rank + 1;
>       h.replace();
>    end;
>
>    ** check all states are inserted;
>
>    do rc = hi.first() by 0 while(rc = 0);
>       if h.find(key:color,key:st) ne 0 then do;
>          state = st;
>          sumval = 0;
>          rank = .;
>       end;
>       rc = hi.next();
>    end;
> end;
> h.output(dataset:'need');
> stop;
> run;
>
> proc print data = need noobs;
> run;
>
> The output of dataset:
>
>
>                                 color     state    sumval    rank
>
>                                 Blue       AK        12        2
>                                 Blue       AZ        20        1
>                                 Blue       NY         0        .
>                                 Green      AK         7        1
>                                 Green      AZ         0        .
>                                 Green      NY         2        2
>                                 Red        AK        10        1
>                                 Red        AZ         5        2
>                                 Red        NY         0        .
>                                 Yellow     AK         0        .
>                                 Yellow     AZ         3        1
>                                 Yellow     NY         0        .
>
>
> Muthia Kachirayan
>
>   On Tue, Mar 2, 2010 at 7:14 PM, Sdlentertd <sdlentertd@gmail.com> wrote:
>
>>  I need help figuring out how to rank my results by state.For each
>> color what is the rank(based on SumVal)  for all states .. I have this
>> SAS dataset
>>
>> State  sumval     Color
>> AK      10           Red
>> AK      12           Blue
>> AK      7              Green
>> AZ       3             Yellow
>> AZ      5              Red
>> AZ     20             Blue
>> NY     2               Green
>>
>> etc...
>> The output will list all states with Rankings  by Color :
>>
>> Red
>> State    SumVal     Rank
>> AK       10                1
>> AZ         5                2
>> NY        0                 .
>>
>> Blue
>> State    SumVal     Rank
>> AK       12                2
>> AZ         20               1
>> NY        0                 .
>>
>> Green
>> State    SumVal     Rank
>> AK       0               .
>> AZ         3               1
>> NY        0                .
>>
>> Green
>> State    SumVal     Rank
>> AK       7                1
>> AZ         0               .
>> NY        2                2
>>
>> So one report for each of Colors (I have 50 or so)
>> and I need to list all 50 states even if the value is 0, and if the
>> value is zero that the rank should be missing.
>> Thank you
>>
>
>
```
 0
Reply muthia.kachirayan (702) 3/4/2010 4:44:43 PM

6 Replies
306 Views

Similar Articles

12/18/2013 1:23:55 PM
page loaded in 137289 ms. (0)

Similar Artilces:

Re: Ranking by State
I really should just wait until data_null_ shows us the direct way to do what you want but, in case you need it right away, I think that the following accomplishes the task: data have; input State \$ sumval Color \$; cards; AK 10 Red AK 12 Blue AK 7 Green AZ 3 Yellow AZ 5 Red AZ 20 Blue NY 2 Green ; proc sort data=have; by color state; run; proc sql noprint; create table need as select unique l.state, r.color from have as l, have as r ...

Re: Ranking by State #4
I was late to read this thread. Mike Zdeb has given a solution based on proc summary and proc rank. I was thinking to use hash objects. It looked difficult at first to incorporate all the needs of the OP in a hash solution. It is not. data have; input state : \$2. sumval color : \$6.; datalines; AK 10 Red AK 12 Blue AK 7 Green AZ 3 Yellow AZ 5 Red AZ 20 Blue NY 2 Green ; run; It needs a presorted data set to get the ranks. A hash table is stored based on the keys of color and state. Another hash table is built to save only the unique colors to check the presence in the former has...

Re: Ranking by State #2
hi ... here's another idea ... data x; input state : \$2. sumval color : \$6.; datalines; AK 10 Red AK 12 Blue AK 7 Green AZ 3 Yellow AZ 5 Red AZ 20 Blue NY 2 Green ; run; proc summary data=x nway completetypes; class color state; var sumval; output out=y (drop=_:) sum=; run; proc rank data=y out=y; var sumval; by color; ranks rank; run; proc print data=y noobs; by color; run; output ... COLOR=Blue state sumval rank AK 12 1 AZ 20 2 ...

Does anyone know where I could find statistics on broadband subscriptions on a state to state basis? thanks! <sorensong@gmail.com> wrote in message news:1131770350.223313.97530@g49g2000cwa.googlegroups.com... > Does anyone know where I could find statistics on broadband > subscriptions on a state to state basis? thanks! > Have you checked www.broadbandreports.com? From: "Kay Archer" <kayhyphenarcher@cableone.net> | <sorensong@gmail.com> wrote in message | news:1131770350.223313.97530@g49g2000cwa.googlegroups.com... >> Does anyone know where I c...

State query in State Pattern
Hi. I have a question about implementing the state pattern in Java. I'm implementing the State abstract base class and each specific class as inner classes of the context class. So I have something like this: Context: Elevator State (inner class of Elevator): ElevatorState Specific States (derived from ElevatorState, inner class of Elevator): DoorOpenState, DoorClosedState So Elevator has a currentState attribute of type ElevatorState. This will be set at any given time to either DoorOpenState or DoorClosedState. My question pertains to implementing a way to query the current state...

State machine: how to stay in a state?
Hi, When writing a vhdl state machine, is there an easy way to stay in a given state for n clock cycles? I always end up having another process with a counter, enable the counter in that particular state, and having a <if count = n> statement in the state transition process. However, the counter needs to be reset in the state before and it ends up being very confusing. Is it possible to do this directly in the state machine process? Thanks Here is the type of state machine I usually use: FSM_transitions: PROCESS (reset, clock) -- synchronous FSM BEGIN If reset = '1' THEN ...

state machine implementation (similar states)
Hi there, I'm currently implementing a processor cache in VHDL. There are the obvious states IDLE, READ_HIT, READ_MISS, READ_MISS_DIRTY, WRITE_HIT, WRITE_MISS, WRITE_MISS_DIRTY. The *_DIRTY states are responsible for writing back the cacheline contents to RAM before reading the new cacheline. So they essentially do the same (i.e. generate the same output signals), except that WRITE_MISS_DIRTY transitions to WRITE_MISS after writing back, and READ_MISS_DIRTY transitions to READ_MISS. So my question is: Is it more efficient to merge the two *_DIRTY states into one and reserve an additiona...

Warning: Rank deficient, rank = 2
Hi there, I'm trying to determine the price of convertible bonds using Least squares Monte Carlo simulation model of Longstaff & Schwartz (2001). I've been running the following codes for a couples of convertible bond and the results are just fine. Coupon = CouponRate * X; DailyCoupon = Coupon/360; CouponCF = zeros(NRepl, NSteps); CouponCF(:,1) = DailyCoupon; for i = 2: 1: NSteps CouponCF(:, i) = CouponCF(:, i-1) + DailyCoupon; end nudt = (mu-0.5*sigma^2)*dt; sidt = sigma*sqrt(dt); RandMat = randn(round(NRepl/2), NSteps); Increments = [nudt + sidt*RandMat ; nudt - sidt*Ra...

State machine outputs and tri-state
Hi I'm not a VHDL expert, just learning, so please don't shout. I'm using Xilinx ISE9.2sp4 and have the following code as part of a state machine: CP_IN_OUTPUT_DECODE: process (state_cp_in) begin if state_cp_in = sta_idle then RDY <= 'Z'; BUSY <= '0'; end if; if state_cp_in = sta_1 then RDY <= '0'; BUSY <= '0'; end if; if state_cp_in = sta_2 then RDY <= '1'; BUSY <= '1'; end if; .... ....etc The state machine goes from sta_idle, then to sta_1, then to sta_2, etc. RDY is a ...