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
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;
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?
Sorry for the bad asking. ID is the grouping. Values in value column are the same for every ID.
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;
thks a lot!
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!
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.
Ready to level-up your skills? Choose your own adventure.