BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
dcortell
Pyrite | Level 9

Hi experts

 

I have the following dataset, where the same id could be present multiple time in combos

 

id sales zone
1   2  "a"
1  3  "b"
1  5  "c"

There is any way to have proc tabulate compute distinct frequencies of "id" ?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Still don't see how you define "unique count". With the table that you show do you mean that "unique" count should be within each Zone? Or overall in the data?

I think that you need to add a variable to you data set that is likely numeric that is assigned a value of one for only one record of each each id and then sum that. But where/how it appears in the table makes a difference on how that variable is made.

 

Note, 3 records, especially without an example of how you want the result to appear is pretty slim to work with.

View solution in original post

6 REPLIES 6
HarrySnart
SAS Employee
Does it need to be PROC TABULATE? You could do this very easily with count distinct in PROC SQL
dcortell
Pyrite | Level 9

Hi Harry

 

I simplified the tabulate code, but it does other other summarization. So yes, I need it in proc tabulate

ballardw
Super User

@dcortell wrote:

Hi Harry

 

I simplified the tabulate code, but it does other other summarization. So yes, I need it in proc tabulate


Show your code.

I ask to see your code because if you want this value in an existing report table then the structure of the remaining code is needed to prevent things like crossing variables incorrectly.

Second, what do you actually expect for out? I am afraid that "unique count of frequencies" may have more than one interpretation. Plus when your example data only shows one value for ID there isn't much clarity about what you are using for input.

 

I suspect that you just need an N statistic in the right place, but do need the rest of your code.

dcortell
Pyrite | Level 9

Sample dataset

id_brandsaleszone
15a
16b
24a

 

Sample code (metacode)

 

proc tabulate data=data;
   class
   id_brand zone;
   var sales;
   table zone,

   sales*sum
   id_brand*N="unique ids" (need unique N of ids) /rts=50
             ;
run;

I'm trying to understand if there is a N distinct approach to use in proc tabulate

ballardw
Super User

Still don't see how you define "unique count". With the table that you show do you mean that "unique" count should be within each Zone? Or overall in the data?

I think that you need to add a variable to you data set that is likely numeric that is assigned a value of one for only one record of each each id and then sum that. But where/how it appears in the table makes a difference on how that variable is made.

 

Note, 3 records, especially without an example of how you want the result to appear is pretty slim to work with.

dcortell
Pyrite | Level 9

Hi Ballard

 

Yes, it was in the end how to I managed the unique count, adding a "1" flag for each unique combination of zone. I was hoping there was some "distinct" statement available in proc tabulate for unique frequencies, but it seems that the way to go is to manipulate the dataset.

 

Thanks

D

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