BookmarkSubscribeRSS Feed
mreynaud
Obsidian | Level 7

Hello,

 

The table below is what I currently have. Lets call it "Test" for this example

2021-11-24_13-16-52.png

What I want is to transpose the phone_type column and have its values contain the phone numbers from the phone_number column.

 

Here is the ideal table I want, we'll call it "Final"

2021-11-24_13-17-08.png

 

I've been trying the following code:

proc transpose data=final out=test;
id phone_type;
var phone_number;
run;

And get this error:

ERROR: The ID value "Home" occurs twice in the input data set.

 

Any help I can get would be wonderful!

3 REPLIES 3
mreynaud
Obsidian | Level 7

Hello,

 

I am trying to create a table called "Final" that will look like this (for this example I am using made up data):

Client_IDClient_NameCellHomeText Message Opt-in
1Kate(111)111-1111(101)010-1010No
2Jack (202) 020-2020 
3Shannon(333)333-3333(303)030-3030Yes
4John(444)444-4444(404) 040-4040No
5Juliet(555)555-5555 Yes
6Sayid(666)666-6666 No
7Claire (707) 070-7070 
8Alex(888)888-8888(808) 080-8080Yes
9Charlie(999)999-9999 No

 

The table I am working from is called "Test". I've been trying to use Proc Transpose for the columns Phone_Type to create two new columns. The two new columns would be Home and Cell and its values would contain the numbers from the Phone_Number column.

Client_IDClient_NamePhone_TypePhone_NumberText Message Opt-in
1KateCell(111)111-1111No
1KateHome(101)010-1010 
2JackHome(202) 020-2020 
3ShannonCell(333)333-3333Yes
3ShannonHome(303)030-3030 
4JohnCell(444)444-4444No
4JohnHome(404) 040-4040 
5JulietCell(555)555-5555Yes
6SayidCell(666)666-6666No
7ClaireHome(707) 070-7070 
8AlexCell(888)888-8888Yes
8AlexHome(808) 080-8080 
9CharlieCell(999)999-9999No

 

Here is the code I've been attempting to use 

proc transpose data=final out=test;
id phone_type;
var phone_number;
run;

I keep on getting an error that says the ID value "Home" occurs twice in the input data set.

 

Any help I can get would be wonderful!

PaigeMiller
Diamond | Level 26

UNTESTED CODE

 

proc transpose data=test out=final;
    by client_id client_name;
    var phone_number;
    id phone_type;
run;

Since we can't program from screen captures, we request that in the future you provide data as SAS data steps (instructions) and then we can give you tested code. So, @mreynaud , please, no more data as screen captures (and also do not provide data as file attachments, as many people will not download them), data only as SAS data steps.

--
Paige Miller

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
  • 795 views
  • 0 likes
  • 3 in conversation