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

I am attempting to extract, transpose, and organize the vigor columns by each species source. I will then repeat this with the Growth form.

My starting data looks like this.

 RowPlotSpecies_sourceVIGOR1Growth_fm1VIGOR2Growth_fm2VIGOR3Growth_fm3VIGOR4Growth_fm4VIGOR5Growth_fm5
 11140031410031
 12222212112323
 13202232323300
 14402231233242

 

I have produced the next table using this code:

proc transpose data=WORK.flaxIn out=Transtrial4(rename=(col1=VigorScore
_name_=Plant_Number)drop=_label_) ;
Title 'Transposed_VigorList';
var Vigor1-Vigor5;
by Species_source NOTSORTED;

run;

Proc print data=Transtrial4;run;

 

vigorpic.jpg

How can I change VIGOR1 - VIGOR5 to Plant1 -Plant 5?

 

Additionally, can I drop the obs column?

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

If I am understanding you properly, you want to change the values of the transposed variable, not the name of the transposed variable. If so ...

 

You can use the TRANWRD function in a DATA step to change the text string VIGOR to the text string PLANT in the output data set.

 

When you do a PROC PRINT, the NOOBS option gets rid of the OBS column.

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

If I am understanding you properly, you want to change the values of the transposed variable, not the name of the transposed variable. If so ...

 

You can use the TRANWRD function in a DATA step to change the text string VIGOR to the text string PLANT in the output data set.

 

When you do a PROC PRINT, the NOOBS option gets rid of the OBS column.

--
Paige Miller
SASsyAndre
Calcite | Level 5

Thank you, you fixed my obs problem! I have a syntax error and or not fully understand what you meant as it hasn't worked yet. Here are some examples of the code I have tried.

 

data change_vigor;
set WORK.flaxIn;
name=tranwrd(name,'Vigor','Plant');
run;

#followed by the previous code I had.

 

and

 

proc transpose data=WORK.flaxIn name=tranwrd(name,'Vigor','Plant') out=Transtrial4(rename=(col1=VigorScore
_name_=Plant_Number)drop=_label_) ;
Title 'Transposed_VigorList';
var Vigor1-Vigor5;
by Species_source NOTSORTED; run;

 

I tried following this guide after your suggestion to use TRANWRD; https://amadeus.co.uk/tips/find-and-replace-in-sas/

PaigeMiller
Diamond | Level 26

You can't use TRANWRD in PROC TRANSPOSE DATA=

 

The proper place to use TRANWRD is in a DATA step after you run PROC TRANSPOSE

--
Paige Miller
SASsyAndre
Calcite | Level 5

It took a lot of tinkering as I am still new to SAS but it eventually got there. THANK YOU!

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
  • 4 replies
  • 1177 views
  • 1 like
  • 2 in conversation