Help using Base SAS procedures

Computing a variable

Reply
N/A
Posts: 0

Computing a variable

I have a dataset that contains a character/string variable (var1).

Is there a way to get the counts (in proc freq) to produce another variable in a new dataset?

For example, the original dataset:

var1
a
a
b
c
c
c

proc freq produces output like this:

var1 frequency
a 2
b 1
c 3

I would like to take the frequency and divide it by another number (ie, 10) to get another variable so that my new dataset looks like this:

var1 frequency new_var
a 2 0.2
b 1 0.1
c 3 0.3

Any help would be appreciated!
Occasional Contributor P_J
Occasional Contributor
Posts: 10

Re: Computing a variable

Posted in reply to deleted_user
Please try below;

data a;
input var1 $;
cards;
a
a
b
c
c
c
;
run;

proc sql;
create table b as
select distinct var1, count(var1) as freq, divide(calculated freq,10) as ave
from a
group by var1;
quit;
N/A
Posts: 0

Re: Computing a variable

Posted in reply to deleted_user
Works wonderfully! Thank you for your help.
Ask a Question
Discussion stats
  • 2 replies
  • 318 views
  • 0 likes
  • 2 in conversation