I have data like below:
Incomplete Incomplete_pct Stalled Stalled_pct Unbegun Unbegun_pct Complete Complete_pct
19751 3.24179 37591 6.16992 146644 24.06911 405276 66.51916
But I would like for my data to look like this:
STATUS COUNT PERCENT
Incomplete 19751 3.2
Stalled 37591 6.2
Unbegun 146644 24.1
Complete 405276 66.5
I was able to create the table I want using the code below. My question is I feel
there should be an easier way. Any suggestions?
proc transpose data = test1 out = test2 (rename=col1=COUNTS _name_ =STATUS));
var incomplete stalled unbegun complete;
run;
proc transpose data = test1 out = test3 (rename=col1=PERCENT _name_ =STATUS_2));
var incomplete_pct stalled_pct unbegun_pct complete_pct;
run;
data combine;
merge test2 test3;
format counts comma8.0 percent 8.1;
run;
Whether it is easier or not but another way is:
data want; set have; array c Incomplete Stalled Unbegun Complete; array r Incomplete_pct Stalled_pct Unbegun_pct Complete_pct; length status $ 10; do i= 1 to dim(c); status = vname(c[i]); count = c[i]; percent= r[i]; output; end; keep status count percent; run;
Which might be preferred if there were additional variables, such as identifiers from the starting records that you would want on each output record. Just add those to the Keep statement.
Why try to fix the data after the fact? Why not go back to the original program that created the data in the wrong format and fix that original program so it generates data in the proper format?
Whether it is easier or not but another way is:
data want; set have; array c Incomplete Stalled Unbegun Complete; array r Incomplete_pct Stalled_pct Unbegun_pct Complete_pct; length status $ 10; do i= 1 to dim(c); status = vname(c[i]); count = c[i]; percent= r[i]; output; end; keep status count percent; run;
Which might be preferred if there were additional variables, such as identifiers from the starting records that you would want on each output record. Just add those to the Keep statement.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: