BookmarkSubscribeRSS Feed
Road_trip
Calcite | Level 5

Hi, Is there a way I can use Formatting in Proc Transpose procedure to format either _name_ or Col. For example, combine below two steps into one?

 

PROC TRANSPOSE DATA=ECG_ OUT=T_ECG2(where=(EGABDESC_^="") rename=(col1=EGABDESC_));
VAR ECGRES1 ECGRES2 ECGRES3;
BY STUDYID USUBJID visit;
RUN;

 

DATA T_ECG2;
SET T_ECG2;
BY STUDYID USUBJID VISIT;
VISIT=PUT(_NAME_, $VISIT.);
RUN;

 

1 REPLY 1
ballardw
Super User

If a single step is critical then you need to do it in manual data step. Something like:

data t_ecg3;
   length visit $ 32;  /*<= need to set the length to hold the longest expected value*/
   set t_ecg2 (drop=visit);
   array vl ECGRES1 ECGRES2 ECGRES3;
   do i=1 to dim (vl);
      visit=put(vname(vl[i]),$visit.);
      col1= vl[i];
      output;
   end;
   drop i ECGRES1 ECGRES2 ECGRES3;
run;

One of the very likely headaches in the attempt is the assigned length of your visit variable and whether the placing the formatted version in to the variable would fit.

 

However, assigning the FORMAT to the variable _name_ should work for many purposes.

 

Note that habitual use of the

data have;

   set have;

 

construct will lead to problems figuring out where your logic problem occurred when something goes unexpected. You completely rewrite the data set and cannot get back to the previous version.

 

 

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 25. 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
  • 1 reply
  • 365 views
  • 0 likes
  • 2 in conversation