BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
max_ros
Obsidian | Level 7

Hello everyone!
I have a dataset where in a column I have repeated but different values for some determinations of another variable (I don't know the number) and I would like to create a new column that contains these values divided by the number of occurrences. How can I do this with simple programming?

Attached the dataset with the "value" column of the values to be divided and the "value_1" column as I would like it (value_1 is the coloumn I 'd like to obtain).
Thanks again for those who want to help me
max

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

If you fix the mis-spellings under ID, this should work (otherwise you don't get the answers you want)

 

proc freq data=example;
    tables id/noprint out=counts;
run;
proc sort data=example;
    by id;
run;
data want;
    merge example counts;
    by id;
    value1 = value/count;
    keep id value value1;
run;
--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

You don't mention the role of ID in this analysis. Is the grouping and the count of the number of occurrences determined by ID or by VALUE?

 

Should we ignore the typographical errors in the ID column and assume that these will always be spelled the same for each value of ID? Or  does the problem solution have to fix the typographical errors first?

--
Paige Miller
max_ros
Obsidian | Level 7

Sorry for the bad asking. ID is the grouping. Values in value column are the same for every ID.

PaigeMiller
Diamond | Level 26

If you fix the mis-spellings under ID, this should work (otherwise you don't get the answers you want)

 

proc freq data=example;
    tables id/noprint out=counts;
run;
proc sort data=example;
    by id;
run;
data want;
    merge example counts;
    by id;
    value1 = value/count;
    keep id value value1;
run;
--
Paige Miller
max_ros
Obsidian | Level 7
tks a lot!

it works perfectly!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1322 views
  • 1 like
  • 2 in conversation