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!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.