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.
Row | Plot | Species_source | VIGOR1 | Growth_fm1 | VIGOR2 | Growth_fm2 | VIGOR3 | Growth_fm3 | VIGOR4 | Growth_fm4 | VIGOR5 | Growth_fm5 | |
1 | 1 | 14 | 0 | 0 | 3 | 1 | 4 | 1 | 0 | 0 | 3 | 1 | |
1 | 2 | 22 | 2 | 2 | 1 | 2 | 1 | 1 | 2 | 3 | 2 | 3 | |
1 | 3 | 20 | 2 | 2 | 3 | 2 | 3 | 2 | 3 | 3 | 0 | 0 | |
1 | 4 | 40 | 2 | 2 | 3 | 1 | 2 | 3 | 3 | 2 | 4 | 2 |
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;
How can I change VIGOR1 - VIGOR5 to Plant1 -Plant 5?
Additionally, can I drop the obs column?
Thank you!
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.
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.
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/
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
It took a lot of tinkering as I am still new to SAS but it eventually got there. THANK YOU!
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.