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.

 

 

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