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

Hi Everyone,

I have a dataset with n variables. I want to create a summary file of distinct/unique values for each variables.


data have;

  input a0 a1 a2 a3 a4 a5 a6;

  datalines;

0 5 9 1 0 8 1

1 4 0 1 0 5 0

1 8 0 1 0 1 1

;

as you see, a0 only take value 0 or 1; a1 values are 5 4 8; a2 values are 9 and 0; a3 take only value 1...

The output file should be:
a0 a1 a2 a3 a4 ...
1  5  9  1  0...
0  4  0
   8


I wonder if there is any simple way to get it done. Right now I can only do it through sort nondupkey one by one and merge, which is not efficient.

Thank you so much for your help.

HHC

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

This looks about right.

data have;
  input a0 a1 a2 a3 a4 a5 a6;
  datalines;
0 5 9 1 0 8 1
1 4 0 1 0 5 0
1 8 0 1 0 1 1
;;;;
   run;
proc summary data=have missing chartype;
  
class a:;
   ways 1;
  
output out=distinct(drop=_type_ _freq_) / levels;
  
run;
proc print;
  
run;

proc sort data=distinct;
   by _level_;
   run;
data flat;
   update distinct(obs=0) distinct;
   by _level_;
   run;
proc print;
  
run;

View solution in original post

6 REPLIES 6
LinusH
Tourmaline | Level 20

Not really summary, rather distinct values?

Without knowing the underlying requirement, it seems like an odd request.

However, I would transpose the data, and the do select distinct/proc sort nodupkey. And if it's really necessary, transpose it back..

Data never sleeps
data_null__
Jade | Level 19

This looks about right.

data have;
  input a0 a1 a2 a3 a4 a5 a6;
  datalines;
0 5 9 1 0 8 1
1 4 0 1 0 5 0
1 8 0 1 0 1 1
;;;;
   run;
proc summary data=have missing chartype;
  
class a:;
   ways 1;
  
output out=distinct(drop=_type_ _freq_) / levels;
  
run;
proc print;
  
run;

proc sort data=distinct;
   by _level_;
   run;
data flat;
   update distinct(obs=0) distinct;
   by _level_;
   run;
proc print;
  
run;

hhchenfx
Barite | Level 11

Thank you so much, Data_null !!!
One quick question since you are here. If the name of variables shares nothing in common, say a1, f4, var1, date... I cannot use the "class a: ;" .

What should we put after "class" so that SAS conduct the proc summary for all variables on the file?

Thank you again,

HHC

Peter_C
Rhodochrosite | Level 12

something like

proc summary missing data= your.data ;

class _all_ ;

output out= results ;

run ;

data_null__
Jade | Level 19

Like says you can use _ALL_  a  SAS Variable List one of the most power features of the SAS language.

hhchenfx
Barite | Level 11

Thank you, Peter and Data_null_.

Lesson learned.

HHC

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1093 views
  • 6 likes
  • 4 in conversation