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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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