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

I need a work around for Proc Transpose. Can you suggest anything?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

@VinitvictorCorr wrote:
lets say

data k;
input subject $ height weight bmi;
datalines;
abc 198 87 22.5
pqr 209 98 25
;
run;

Try this:

data want;
set k;
array vars _numeric_;
length name $32 value 8;
do i = 1 to dim(vars);
  name = vname(vars{i});
  value = vars{i};
  output;
end;
keep subject name value;
run;

View solution in original post

22 REPLIES 22
VinitvictorCorr
Quartz | Level 8
just want to explore myoptions 🙂
PeterClemmensen
Tourmaline | Level 20

Please be more specific than this.

 

Explain why you want to avoid PROC TRANSPOSE. This makes it easier to understand your problem.

VinitvictorCorr
Quartz | Level 8
no particular reason..just want one more option in my bag
KachiM
Rhodochrosite | Level 12

@VinitvictorCorr 

 

One way is to use Array.

 

Give a Data Set, give explanation for transposing with the expected output data set. It will be then easier to help you.

VinitvictorCorr
Quartz | Level 8
lets say

data k;
input subject $ height weight bmi;
datalines;
abc 198 87 22.5
pqr 209 98 25
;
run;
KachiM
Rhodochrosite | Level 12

@VinitvictorCorr 

 

Your data is Ok. How do you want to re-shape it without using Proc Transpose? Show your Shape.

VinitvictorCorr
Quartz | Level 8
@KachiM
I need the output like:-
subject vstestcd vsorres
KachiM
Rhodochrosite | Level 12

@VinitvictorCorr 

 

You have given a Data Set as:

data k;
input subject $ height weight bmi;
datalines;
abc 198 87 22.5
pqr 209 98 25
;
run;

I don't see the variable names as given now as:

subject vstestcd vsorres

Please clarify your correct specification. 

VinitvictorCorr
Quartz | Level 8
the output will be like


SUBJECT VSTESTCD VSORRES
abc Height 198
abc Weight 87
abc BMI 22.5
pqr height 209
pqr weight 98
pqr BMI 25
Kurt_Bremser
Super User

@VinitvictorCorr wrote:
the output will be like


SUBJECT VSTESTCD VSORRES
abc Height 198
abc Weight 87
abc BMI 22.5
pqr height 209
pqr weight 98
pqr BMI 25

I already gave you code for that, you only need to change variable names.

KachiM
Rhodochrosite | Level 12

@VinitvictorCorr 

 

My program is similar to @Kurt_Bremser .

 

data k;
input SUBJECT $ height weight bmi;
datalines;
abc 198 87 22.5
pqr 209 98 25
;
run;

The following data step uses an array to hold the Labels for names of the variables (Height, Weight, BMI). Another array (V) is used to get the values of the variables. Using Do-Loop they are individually output to the new Data Set (WANT).

 

data want;
   array names[3] $ ('Height', 'Weight', 'BMI');
   set k;
   array v height -- bmi;
   do j = 1 to dim(v);
      VSTESTCD = names[j];
      VSORRES = v[j];
      output;
   end;
keep SUBJECT VSTESTCD VSORRES;
run;

The output is:

 

trans.JPG

VinitvictorCorr
Quartz | Level 8
Thank you 🙂

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 22 replies
  • 2483 views
  • 2 likes
  • 9 in conversation