SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
Aswanth
Calcite | Level 5

In proc freq can i use nodupkey....

 

if it possible means how can i use....

 

4 REPLIES 4
LinusH
Tourmaline | Level 20

https://communities.sas.com/t5/Getting-Started/How-to-get-fast-helpful-answers/ta-p/226133

 

So in other words,

have a descriptive subject (other than the name of the SW we all are using), and and formulate the question so that your grand parents can understand it. Including sample have and want data.

Data never sleeps
Kurt_Bremser
Super User

First of all, using "sas" as the subject for a question on the SAS forum is, ahem, not very informative.

 

Second, you seem to misunderstand the use of proc freq. There will only be one line of output (or one observation in the output dataset) for every single value in a given variable counted witrh proc freq, so nodupkey is useless.

 

If you only want to get a count (or list) of distinct values, do that in SQL:

proc sql;
select distinct sex from sashelp.class;
select count(distinct sex) from sashelp.class;
quit;
Reeza
Super User

Use two PROC FREQs or use DISTINCT in SQL. 

 

/*This demonstrates how to count the number of unique occurences of a variable
across groups. It uses the SASHELP.CARS dataset which is available with any SAS installation.
The objective is to determine the number of unique car makers by origin/

Note: The SQL solution can be off if you have a large data set and these are not the only two ways to calculate distinct counts.
If you're dealing with a large data set other methods may be appropriate.*/

*Count distinct IDs;
proc sql;
create table distinct_sql as
select origin, count(distinct make) as n_make
from sashelp.cars
group by origin;
quit;

*Double PROC FREQ;
proc freq data=sashelp.cars noprint;
table origin * make / out=origin_make;
run;

proc freq data=origin_make noprint;
table origin / out= distinct_freq;
run;

title 'PROC FREQ';
proc print data=distinct_freq;
run;
title 'PROC SQL';
proc print data=distinct_sql;
run;

 

https://github.com/statgeek/SAS-Tutorials/blob/master/count_distinct_by_group

Astounding
PROC Star

Just in case it isn't clear from the answers you received, the answer is No.

 

The only procedure that uses NODUPKEY is PROC SORT.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 7268 views
  • 4 likes
  • 5 in conversation