Hello
What is the way to label the following variables during proc transpose .
Label of variable Wealth1 will be Stocks wealth1
Label of variable Wealth2 will be Stocks wealth2
Label of variable Wealth3 will be Stocks wealth3
Label of variable Wealth4 will be Stocks wealth4
Label of variable Wealth5 will be Stocks wealth15
Data have;
label wealth='Stocks wealth';
input CustID month wealth;
cards;
1 2101 10
1 2102 20
1 2103 30
1 2104 40
1 2105 50
2 2101 5
2 2102 10
2 2103 15
2 2104 20
2 2105 25
;
Run;
proc transpose data=have out=Want (drop=_name_ ) prefix=wealth;
VAR wealth ;
BY CustID ;
Run;
Prepare the wanted names and labels in a preceding step, and use the ID and IDLABEL statements of PROC TRANSPOSE
Thanks, however during transpose from long to wide there is no need to use ID statement.
What is the way to add the labels?
@Ronein wrote:
Thanks, however during transpose from long to wide there is no need to use ID statement.
What is the way to add the labels?
The IDLABEL statement.
So you need to create the labels first.
After all this time, with @Kurt_Bremser and myself and others constantly advising you to avoid wide data sets, I am surprised that you keep using wide data sets. The best thing to do would be to leave the data as long, and then programming is sooooo much easier.
I need to prepare a data panel with one row per customer and from this panel will create reports in Tableu.
This is the reason for wide structure.
Do you still think that it is wrong (for using panel)?
Can't Tableau create reports from long data? I'd be surprised.
Just supply Tableau with the long data -prepared as needed- and let Tableau present it.
I (of course) concur with @PaigeMiller about the uselessness of wide datasets, see Maxim 19.
Wide reports can easily be done with PROC REPORT.
Modify your prefix in proc transpose as follows
proc transpose data=have out=Want (drop=_name_ _LABEL_) prefix='Stocks Wealth'n;
VAR wealth ;
BY CustID ;
Run;
Your output will be like this
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.