BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mona4u
Lapis Lazuli | Level 10

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20
Indeed, proc transpose data=table4 out=rotate(rename=(_NAME_=VS COL1=VV)); run; does exactly what you want.

View solution in original post

3 REPLIES 3
ballardw
Super User

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.

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 1655 views
  • 2 likes
  • 3 in conversation