## Rotating a data set

Solved
Regular Contributor
Posts: 150

# Rotating a data set

Hi,

I'm trying to rotate my data and this is my first time doing this.

Please edit my code if you can

this is the data set that I have

 Obs case_assigned Time_points_read Time_points_complete Readable_Time_Points Time_Points_Pending off_study off_study_Total 1 5 53 1360 15 15 0 0

and this is the result that I got

 Obs case_assigned Time_points_read Time_points_complete Readable_Time_Points Time_Points_Pending off_study off_study_Total i vv vs 1 5 53 1360 15 15 0 0 1 5 Cases Assigned 2 5 53 1360 15 15 0 0 2 53 Cases Assigned 3 5 53 1360 15 15 0 0 3 1360 Cases Assigned 4 5 53 1360 15 15 0 0 4 15 Cases Assigned 5 5 53 1360 15 15 0 0 5 15 Cases Assigned 6 5 53 1360 15 15 0 0 6 0 Cases Assigned 7 5 53 1360 15 15 0 0 7 0 Cases Assigned

and this is the aim

 vv vs 5 Cases Assigned 53 Time_points_read 1360 Time_points_complete 15 Readable_Time_Points 15 Time_Points_Pending 0 off_study 0 off_study_Total

and this is my code

data rotate;
set table4;
Time_Points_Pending off_study off_study_total;
do i=1 to 7;
if var{7} ne . then do;
vv=var{i};
vs= ("Cases Assigned" );
output;
end;
end;
run;

Accepted Solutions
Solution
‎04-03-2018 09:06 AM
PROC Star
Posts: 2,318

## Re: Rotating a data set

Indeed, proc transpose data=table4 out=rotate(rename=(_NAME_=VS COL1=VV)); run; does exactly what you want.

All Replies
Super User
Posts: 13,321

## Re: Rotating a data set

Do you want a data set for further manipulation or a report for people to read?

Untested but you were close with the data :

data rotate;
set table4;
Time_Points_Pending off_study off_study_total;
do i=1 to 7;
if var{7} ne . then do;
vv=var{i};
vs= vname(var{I});
output;
end;
end;
keep vv vs;
run;

The keep says to only have the variable vv and vs in the output data set.

The VNAME function will return the name of the variable the array index points to.

You really should specify the length of the VS variable before use as many times the length result for functions will default to either largish values (200 in the case of vname) or possibly to short because of the first value you assign isn't the longest.

Solution
‎04-03-2018 09:06 AM
PROC Star
Posts: 2,318

## Re: Rotating a data set

Indeed, proc transpose data=table4 out=rotate(rename=(_NAME_=VS COL1=VV)); run; does exactly what you want.
PROC Star
Posts: 2,318

## Re: Rotating a data set

@dgritt scroll right.. .

☑ This topic is solved.