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

Hi!

 

First time poster so please excuse anything I miss.

 

I work with confidential data so I won't be able to post the details here but essentially what I'm trying to do is create one column that has multiple variables (a scale if you will) and assign that scale to each observation.

 

Table 1 looks like this

AccountAccount Number
AlphaABC1
BetaABC2
DeltaABC3

 

And I want the output to look like this:

AccountAccount NumberScale
AlphaABC11
AlphaABC12
AlphaABC13
BetaABC21
BetaABC22
BetaABC23
DeltaABC31
DeltaABC32
DeltaABC33

 

Any advice?

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Hi and welcome to the SAS Community.

 

For a first time poster, you're doing very well 🙂 Nice explanation and data we can work with.

 

Try the code below and see if it works. Feel free to ask.

 

data have;
input Account $ AccountNumber $;
datalines;
Alpha ABC1
Beta  ABC2
Delta ABC3
;

data want;
   set have;
   do scale = 1 to 3;
      output;
   end;
run;

 

Result:

 

Account  AccountNumber  scale 
Alpha    ABC1           1 
Alpha    ABC1           2 
Alpha    ABC1           3 
Beta     ABC2           1 
Beta     ABC2           2 
Beta     ABC2           3 
Delta    ABC3           1 
Delta    ABC3           2 
Delta    ABC3           3 

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Hi and welcome to the SAS Community.

 

For a first time poster, you're doing very well 🙂 Nice explanation and data we can work with.

 

Try the code below and see if it works. Feel free to ask.

 

data have;
input Account $ AccountNumber $;
datalines;
Alpha ABC1
Beta  ABC2
Delta ABC3
;

data want;
   set have;
   do scale = 1 to 3;
      output;
   end;
run;

 

Result:

 

Account  AccountNumber  scale 
Alpha    ABC1           1 
Alpha    ABC1           2 
Alpha    ABC1           3 
Beta     ABC2           1 
Beta     ABC2           2 
Beta     ABC2           3 
Delta    ABC3           1 
Delta    ABC3           2 
Delta    ABC3           3 
Pattyp33
Fluorite | Level 6

THANK YOU!! It worked perfectly!

 

Those dang do statements, something I should have payed more attention to in school lol

 

Thank you again!

novinosrin
Tourmaline | Level 20

Hi @Pattyp33  Sorry just noticed the thread already answered. One could think through other ways if we care-


data have;
input Account $ AccountNumber $;
datalines;
Alpha ABC1
Beta  ABC2
Delta ABC3
;
/*Create VIEW of your scale*/
data temp/view=temp;
 do scale=1 to 3;
  output;
 end;
run;
/*Cross join */
proc sql;
 create table want as
 select a.*,scale
 from have a,temp
 order by accountnumber, scale;
quit;

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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