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;
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;
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.
@dgritt scroll right.. . 🙂
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.