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