Search code examples
sasunique-values

append three variables from the same dataset SAS


I want to create a variable which would have unique values of each variable present in the dataset.

I have a dataset with three variables and some unique values in each of them.

Example:

var1 Var2 Var3
 1     4    5
 1     3    7
 2     8    6
 3     2    9
 1     1    3
 4     5    6
 5     7    8

I want to extract unique values for each variable and append them to form one variable.

I want the dataset to look like

var4 1,2,3,4,5,6,7,8,9. 

values present in var4 are unique values from var1, var2 & var3.

Please help me in writing code in SAS for this.


Solution

  • proc sql;
    create table allvars as 
    select var1 from dataset
    union
    select var2 from dataset
    union
    select var3 from dataset;
    quit;