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!

sas-innovate-2024.png

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.

 

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