BookmarkSubscribeRSS Feed
shuvaya
Calcite | Level 5

Hi,

 

For the attached screenshot I want to have the values under __NAME__ appended to existing column names:

 

shuvaya_1-1665381372902.png

 

 

So output dataset will have only one row for a customer which will have column names snack_net_amount , breakfast_net_amount , snack_num_txns , breakfast_num_txns.

Can someone please help me with this?

I think I am missing something very basic, but since I am new to SAS, can't seem to figure it out.

2 REPLIES 2
ballardw
Super User

Provide example data in the form of a data step. We can't write code to use a screen shot.

Then provide what you expect as a result.

If your "customerid" values are so sensitive replace them in the example with some different values like XXXX and YYYY or similar.

 

Since a number of SAS procedures will create a variable like _NAME_ in the process it might be that you should share the data from before whatever you have done to create that example and show us the code used to create it. It may be that is the step to do this instead of afterwards.

 

Are you sure that you need a data set?

Ksharp
Super User
/*
As ballarwd pointed out.
Make a data step to represent your data,Nodoby would like to type it for you !
*/
data have;
input id name $ snack breakfast;
cards;
1 net_amou 27.97 1
1 num_txns 1  2
2 net_amou 27.97 1
2 num_txns 1  2
;

data temp;
 set have;
 n+1;
run;

proc transpose data=temp out=temp2;
by  n id name;
var  snack breakfast;
run;
proc transpose data=temp2 out=want delimiter=_;
by id;
id _name_ name;
var col1;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 225 views
  • 0 likes
  • 3 in conversation