BookmarkSubscribeRSS Feed
tmtemples
Fluorite | Level 6

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;

2 REPLIES 2
ballardw
Super User

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.

LinusH
Tourmaline | Level 20
The only (?) safe structure in SAS where you can combine details and aggregations are OLAP cubes.
Data never sleeps

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 758 views
  • 0 likes
  • 3 in conversation