BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

image.png

View solution in original post

4 REPLIES 4
himself
Pyrite | Level 9

 

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. 

 

 

Ronein
Meteorite | Level 14

Hello,

As you can see in the code you wrote there are no labels in the new data set that was created

Tom
Super User Tom
Super User

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;

image.png

Ronein
Meteorite | Level 14
You are the best!!
Thank you

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1121 views
  • 1 like
  • 3 in conversation