DATA Step, Macro, Functions and more

Rotating a data set

Accepted Solution Solved
Reply
Regular Contributor
Posts: 150
Accepted Solution

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                       

Obscase_assignedTime_points_readTime_points_completeReadable_Time_PointsTime_Points_Pendingoff_studyoff_study_Total
15531360151500

 

and this is the result that I got 

Obscase_assignedTime_points_readTime_points_completeReadable_Time_PointsTime_Points_Pendingoff_studyoff_study_Totalivvvs
1553136015150015Cases Assigned
25531360151500253Cases Assigned
3553136015150031360Cases Assigned
45531360151500415Cases Assigned
55531360151500515Cases Assigned
6553136015150060Cases Assigned
7553136015150070Cases Assigned

 

and this is the aim 

 

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

and this is my code 

data rotate;
set table4;
array var{7} case_assigned Time_points_read Time_points_complete Readable_Time_Points
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.

View solution in original post


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;
   array var{7} case_assigned Time_points_read Time_points_complete Readable_Time_Points
   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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 160 views
  • 2 likes
  • 3 in conversation