I used the code below to combine the results of primary reasons that came in several columns in a spreadsheet. This works to give me the frequency of each of the responses; however, i would like to keep the result associated with the original data set so I can see how each unit type responded. Any suggestions on how to either include the unit type in these results, or merge this table back with the original? Thanks!
PROC SQL ;
CREATE TABLE REASONS AS
SELECT PRIMARY_REASON, COUNT(1) AS FREQS
FROM (SELECT PRIMARY_REASON1 AS PRIMARY_REASON FROM DEEP_DIVE2 UNION ALL
SELECT PRIMARY_REASON2 AS PRIMARY_REASON FROM DEEP_DIVE2 UNION ALL
SELECT PRIMARY_REASON3 AS PRIMARY_REASON FROM DEEP_DIVE2 UNION ALL
SELECT PRIMARY_REASON4 AS PRIMARY_REASON FROM DEEP_DIVE2 UNION ALL
SELECT PRIMARY_REASON5 AS PRIMARY_REASON FROM DEEP_DIVE2 UNION ALL
SELECT PRIMARY_REASON6 AS PRIMARY_REASON FROM DEEP_DIVE2 UNION ALL
SELECT PRIMARY_REASON7 AS PRIMARY_REASON FROM DEEP_DIVE2 UNION ALL
SELECT PRIMARY_REASON8 AS PRIMARY_REASON FROM DEEP_DIVE2
) AS MYUNION
GROUP BY PRIMARY_REASON
ORDER BY 2 DESC ;
QUIT;
This request probably should have a small example input data, preferably in the form of a datastep if you want tested code, and what you would expect the result to look like, also as a datastep would be best.
It sounds like you want to put some sort of aggregate value along with the original values into a single dataset. This is a potentially dangerous data structure if someone else could use that data or if you forget that some values are aggregates in another processing step.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.