SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
SNG1
Calcite | Level 5

SAS.jpg

Hi All,

 

I am bit new to SAS, I searched the boards but could not find an answer to the dilemma I am facing -

 

I have a SAS Data Set that looks like the attached picture, as you can see that Once address could have multiple phone numbers and/or multiple First Name. I am trying to transpose this data do I can see it something like this (as headings and then the data underneath) -

 

Address    First Name1    First Name2    FirstName...n    Phone1    Phone2     Phone3     Phone4    Phone...n

 

For Example for  first two records, I would like to see:

 

1 52 2 Niagara     Menzies Justin    Menzies Justin    5198450640     5198451608

 

if there are multiple names or phone numbers then a extra column gets added for each...

 

 

Any help is much appreciated....Thanks!

 

2 REPLIES 2
Reeza
Super User

You're transposing multiple varialbes so you'll need to eitehr:

1. Use an ARRAY() https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/

2. Use multiple PROC TRANSPOSE and merge the results. https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/

 

The latter is usually easier if you're a beginner. 

 

There's a macro called 'A Better Way to Flip" and you can use that to get what you want as well. 

http://www.sascommunity.org/wiki/A_Better_Way_to_Flip_(Transpose)_a_SAS_Dataset

 


@SNG1 wrote:

SAS.jpg

Hi All,

 

I am bit new to SAS, I searched the boards but could not find an answer to the dilemma I am facing -

 

I have a SAS Data Set that looks like the attached picture, as you can see that Once address could have multiple phone numbers and/or multiple First Name. I am trying to transpose this data do I can see it something like this (as headings and then the data underneath) -

 

Address    First Name1    First Name2    FirstName...n    Phone1    Phone2     Phone3     Phone4    Phone...n

 

For Example for  first two records, I would like to see:

 

1 52 2 Niagara     Menzies Justin    Menzies Justin    5198450640     5198451608

 

if there are multiple names or phone numbers then a extra column gets added for each...

 

 

Any help is much appreciated....Thanks!

 


 

SNG1
Calcite | Level 5

Thanks...worked perfect

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 844 views
  • 0 likes
  • 2 in conversation