BookmarkSubscribeRSS Feed
miris
Fluorite | Level 6

origin file 

group   weight01 weight02  weight03   

A   1 2 3

A    4 5 6 

B    7 8 9

B    6 5 4

 

I woul like to

group   weight

 A 1

A 4

B 7

B 6

A 2

A 5

B 8

B 5

A 3

A 6

B 9

B 4

4 REPLIES 4
miris
Fluorite | Level 6

I think I find the answer.

 

it is folowing logic

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

 

Kurt_Bremser
Super User

@miris wrote:

I think I find the answer.

 

it is folowing logic

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

 


Correct version (giving exactly the output you initially posted):

proc sql;
create table allvars as 
select group, weight01 as weight from have
union all
select group, weight02 as weight from have
union all
select group, weight03 as weight from have;
quit;
Kurt_Bremser
Super User

Explicit method in a data step:

data want;
set have;
array weights {*} weight01-weight03;
do i = 1 to dim(weights);
  weight = weights{i};
  output;
end;
keep group weight;
run;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Or simply:

data want;
  set have (rename=(weight01=weight))
      have (rename=(weight02=weight))
      have (rename=(weight03=weight));
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 878 views
  • 0 likes
  • 3 in conversation