BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

Hello:

 

I would like to count the group frequency of the two columns "Analysis" and "Product" in test1 table below.  Please advice how to approach.  Thanks.

 

data test1; 
      infile datalines dlm='|'; 
  input name : $20. Analysis : $100. Product : $100.; 
datalines;                  
Ali| Cleft Lip +/- Palate|  LABETOLOL|   
Ali| Cleft Lip +/- Palate|  ATENOLOL|   
Ali| VSDs (Excludes VSDavc)|  ATENOLOL|  
Ali| VSDs (Excludes VSDavc)|  FLUCONAZOLE| 
Carol| Choanal Atresia|  LEVOTHYROXINE SODIUM|   
Carol| Cleft Lip +/- Palate|  ATENOLOL|   
Carol| Intestinal Atresia/Stenosis|  EPHEDRA|  
Malyn| TGA +/- DORV|  ALBUTEROL SULFATE|  
Malyn|  TOF +/- PA, DORV -TGA|  BUTALBITAL| 
Malyn| Esoph Atresia +/- TEF|  FLONASE|   
; 

proc sort data=test1; by analysis; run;

 

 

 

The result I am looking for is:

Analysis                                            Count

Cleft Lip +/- Palate                            3

VSDs (Excludes VSDavc)                 2

Choanal Atresia                                1

Intestinal Atresia/Stenosis                1

TGA +/- DORV                                 1

TOF +/- PA, DORV -TGA                 1

Esoph Atresia +/- TEF                     1

 

Product

LABETOLOL                                   1

ATENOLOL                                     2

FLUCONAZOLE                             1

LEVOTHYROXINE SODIUM          1

EPHEDRA                                       1

ALBUTEROL SULFATE                  1

BUTALBITAL                                   1

FLONASE

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Please post example code  in a code box opened with either the {I} or running man icon.

Please.

Do you really want a record of data with no values (the blank dataline)?

 

Is the ORDER of the appearance important? If so you might specify the rules.

If I wanted the output in descending order of frequency I would start with

proc freq data=test1 order=freq;
   tables analysis product /nocum nopercent;
run;

View solution in original post

6 REPLIES 6
ballardw
Super User

Please post example code  in a code box opened with either the {I} or running man icon.

Please.

Do you really want a record of data with no values (the blank dataline)?

 

Is the ORDER of the appearance important? If so you might specify the rules.

If I wanted the output in descending order of frequency I would start with

proc freq data=test1 order=freq;
   tables analysis product /nocum nopercent;
run;
ybz12003
Rhodochrosite | Level 12

I don't know how to post example code in a code box opened with either the {I} or running man icon.   I add { } before and after my codes.  Does it help?

 

How to generate a permeant SAS dataset instead of in the "result viewer"?   Is there a way to output in one table?  Thanks.

Reeza
Super User

You should learn how. It makes it easier on us to help you.

 

delete_insert_code.JPG

 

And please try reading the documentation BEFORE asking questions. 

The first example in PROC FREQ:

Example 3.1 Output Data Set of Frequencies

 

http://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.2&docsetId=procstat&docsetTarget=proc...

 


@ybz12003 wrote:

I don't know how to post example code in a code box opened with either the {I} or running man icon.   I add { } before and after my codes.  Does it help?

 

How to generate a permeant SAS dataset instead of in the "result viewer"?   Is there a way to output in one table?  Thanks.


 

ballardw
Super User

@ybz12003 wrote:

 

How to generate a permeant SAS dataset instead of in the "result viewer"?   Is there a way to output in one table?  Thanks.


Proc freq can create one output data set per tables request which would be for one variable. You could append two data sets to get one though.

 

HOW would you use the single data set with both variables summarized? There can be significant issues in what needs to be done to use such a summarized set depending on exact usage.

Reeza
Super User

You can use ODS to get both into one table, demoed below

 

https://gist.github.com/statgeek/e0903d269d4a71316a4e

ybz12003
Rhodochrosite | Level 12

Thanks for all your great suggestion.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 6 replies
  • 797 views
  • 3 likes
  • 3 in conversation