BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sameer112217
Quartz | Level 8

 

Need help, I have an input table like this. I want to transpose the values in agriemail and sigrimeial against cluster and cluster1 in rows from columns

 

Input Table    
CLUSTERCLUSTER1 AGRIEMAILSIGRIEMAIL
AJMERAGRI PROD sameer1122@yahoo.comhardik@yahoo.com
AJMERAGRI PROD amit1122@yahoo.comumran@yahoo.com
AJMERAGRI PROD nikhil@yahoo.comrahul@yahoo.com
SURATSIGRI GOLD rajesh@yahoo.comvirat@yahoo.com
SURATSIGRI GOLD Kranti@yahoo.comrohit@yahoo.com
SURATSIGRI GOLD Nitin@yahoo.comshami@yahoo.com

 

Want output like this

 

CLUSTERCLUSTER1 Email1Email2Email3 
AJMERAGRI PROD sameer1122@yahoo.comamit1122@yahoo.comnikhil@yahoo.com 
AJMERAGRI PROD sameer1122@yahoo.comamit1122@yahoo.comnikhil@yahoo.com 
AJMERAGRI PROD sameer1122@yahoo.comamit1122@yahoo.comnikhil@yahoo.com 
SURATSIGRI GOLD virat@yahoo.comrohit@yahoo.comshami@yahoo.com 
SURATSIGRI GOLD virat@yahoo.comrohit@yahoo.comshami@yahoo.com 
SURATSIGRI GOLD virat@yahoo.comrohit@yahoo.comshami@yahoo.com

 

 

 

 

 

 

It can be email 1-50. Tried Proc Transpose but it did not work

 

Proc Transpose data = sample out=output

by  cluster cluster1;

id email1

var agriemail sigriemail;

run;

 

Not getting desired output.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You don't show any variable named EMAIL1 which the posted code is trying to use as the source of the NAME of new variables.  But it does not look like you need or want one.

 

Instead use the PREFIX= option.

proc Transpose data = sample out=output prefix=email ;
  by  cluster cluster1;
  var agriemail sigriemail;
run;

 So you will get two observations per CLUSTER, CLUSTER1 combination with as many EMAIL columns as needed.

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

You don't show any variable named EMAIL1 which the posted code is trying to use as the source of the NAME of new variables.  But it does not look like you need or want one.

 

Instead use the PREFIX= option.

proc Transpose data = sample out=output prefix=email ;
  by  cluster cluster1;
  var agriemail sigriemail;
run;

 So you will get two observations per CLUSTER, CLUSTER1 combination with as many EMAIL columns as needed.

PaigeMiller
Diamond | Level 26

Is the issue that when CLUSTER1='AGRI PROD' you want to transpose Agriemail and when CLUSTER1='SIGRI GOLD' then you want to transpose SIGRIEMAIL? Are there more than two values of CLUSTER1? 

 

In the output ,why are there three identical rows for AJMER and three identical rows for SURAT? Why don't you want one row for AJMET and one row for SURAT?


@sameer112217 

 

We usually require data to be presented as working SAS data step code (instructions). We can't work with data presented as screen captures. Please provide data in an acceptable form. Thanks!

--
Paige Miller
mkeintz
PROC Star

I have no idea of what reorganization rules you want to apply.  For one cluster/cluster1 combination you transpose agriemail, for the other combinations you transpose sigriemail.  What is the rule for making this distinction?  If it is the value of cluster1, then how many possible values of cluster1 are there?

 

Why are you producing duplicate records, given all the information is contained in one output record?  If you start out with 10 records for a given cluster/cluster1, do you intend to populate 10 variables, and also 10 duplicate records?

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

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