Help using Base SAS procedures

Counting Variables

Reply
Frequent Contributor
Posts: 122

Counting Variables

Hi,

Could you please help me with the following requirement:

I have a dataset like the following:

State  Visited

-------   ----------

CA      Y

NV       Y

NV      Y

NV      N

NV       N

GA      N

I need to have an output dataset like the following:

State      Yes   No

-------       ----    ----

CA          1      0

NV          2      2

GA          0      1

Please share your thoughts

Thanks

PROC Star
Posts: 7,471

Counting Variables

Here is one of many ways:

data have;

  input (State  Visited) ($);

  cards;

CA      Y

NV       Y

NV      Y

NV      N

NV       N

GA      N

;

proc sql;

  select state,

         sum(visited="Y") as Yes,

         sum(Visited="N") as No

    from have

      group by state

  ;

quit;

Frequent Contributor
Posts: 122

Counting Variables

Thanks so much!

Ask a Question
Discussion stats
  • 2 replies
  • 122 views
  • 0 likes
  • 2 in conversation