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!

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 416 views
  • 5 likes
  • 3 in conversation