0
votes

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.

2

2 Answers

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

/*Get values from columns into single column*/
proc sql;
create table var4 as
select distinct var1 from tablename
union
select distinct var2 from tablename
union
select distinct var3 from tablename;
quit;