Hello
What is the way that wanted data set will have labels for columns same as variables names?
It means that :
label of variable Wealth1 will be Wealth1
label of variable Wealth2 will be Wealth2
label of variable Wealth3 will be Wealth3
label of variable Wealth4 will be Wealth4
label of variable Wealth5 will be Wealth5
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;
I don't understand what you want.
If you want the output dataset not to have the variable _LABEL_ then either drop it like you did _NAME_ or remove the label in the PROC TRANSPOSE step.
proc transpose data=have out=Want (drop=_name_ ) prefix=wealth;
by CustID ;
var wealth ;
label wealth=' ';
run;
If the want the LABEL to be the same as the NAME then just leave the LABEL empty and where ever SAS would normally display the label instead of the name it will just use the name. Try it yourself and see.
proc print data=want;
run;
proc print data=want label;
run;
If you want to have full control over the name (and label) then add those variables to your data and use the ID and IDLABEL statements.
data for_transpose;
set have;
by custid ;
length name $32 label $256 ;
name=cats('wealth',month);
label=catx(' ','Wealth for month',month);
run;
proc transpose data=for_transpose out=Want (drop=_name_ );
by CustID ;
id name;
idlabel label;
var wealth ;
run;
proc transpose data=have out=Want (drop=_name_ _label_) prefix=wealth;
VAR wealth ;
BY CustID ;
idlabel wealth;
Run;
NB: So the following works, but i think you might need to have a variable which creates a name for the value that was transposed.
If the variable was present, then we would have used an id statement.
Hello,
As you can see in the code you wrote there are no labels in the new data set that was created
I don't understand what you want.
If you want the output dataset not to have the variable _LABEL_ then either drop it like you did _NAME_ or remove the label in the PROC TRANSPOSE step.
proc transpose data=have out=Want (drop=_name_ ) prefix=wealth;
by CustID ;
var wealth ;
label wealth=' ';
run;
If the want the LABEL to be the same as the NAME then just leave the LABEL empty and where ever SAS would normally display the label instead of the name it will just use the name. Try it yourself and see.
proc print data=want;
run;
proc print data=want label;
run;
If you want to have full control over the name (and label) then add those variables to your data and use the ID and IDLABEL statements.
data for_transpose;
set have;
by custid ;
length name $32 label $256 ;
name=cats('wealth',month);
label=catx(' ','Wealth for month',month);
run;
proc transpose data=for_transpose out=Want (drop=_name_ );
by CustID ;
id name;
idlabel label;
var wealth ;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.