BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
luvscandy27
Quartz | Level 8

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

 

View solution in original post

3 REPLIES 3
Astounding
PROC Star

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?

ballardw
Super User

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.

 

luvscandy27
Quartz | Level 8
That works! Thank you!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 814 views
  • 5 likes
  • 3 in conversation