DATA Step, Macro, Functions and more

How do I combine results from across several columns of data

Reply
Occasional Contributor
Posts: 17

How do I combine results from across several columns of data

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;

Super User
Posts: 10,500

Re: How do I combine results from across several columns of data

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.

Super User
Posts: 5,257

Re: How do I combine results from across several columns of data

The only (?) safe structure in SAS where you can combine details and aggregations are OLAP cubes.
Data never sleeps
Ask a Question
Discussion stats
  • 2 replies
  • 191 views
  • 0 likes
  • 3 in conversation