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
This looks about right.
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..
This looks about right.
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
something like
proc summary missing data= your.data ;
class _all_ ;
output out= results ;
run ;
Like says you can use _ALL_ a SAS Variable List one of the most power features of the SAS language.
Thank you, Peter and Data_null_.
Lesson learned.
HHC
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.
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.