I have 400 clusters (20,000 observations). I want to get proportion of smokers in each cluster (Smoking vs non-smoking) as a separate variable in the same data set for each cluster. I would really appreciate the help from helping hands.
Thanks
DUPLICATE THREAD
DO NOT REPLY HERE
Reply at: https://communities.sas.com/t5/SAS-Programming/Calculating-proportion/td-p/623140 where there is already one answer.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
The example data only needs to include the variables needed to identify a cluster and your smoking variable.
Then show what you expect as a result.
In the same data set is possibly not a good idea as mixing summaries and observation values has the potential for oddness when someone forgets which variable is a summary. Can you describe exactly why you need the summary proportion on each record?
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.