BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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!
2 REPLIES 2
P_J
Calcite | Level 5 P_J
Calcite | Level 5
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;
deleted_user
Not applicable
Works wonderfully! Thank you for your help.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1061 views
  • 0 likes
  • 2 in conversation