BookmarkSubscribeRSS Feed
srikanthyadav44
Quartz | Level 8

dear all 

I have to repeat each value of a variable for ten times.  

i have do it for 357 values

my data set format is as follows

companycode

comp1
comp2
comp3
………….
………
…………
comp357

 

required format is

companycode
comp1
comp1
comp1
comp1
comp1
comp1
comp1
comp1
comp1
comp1
comp2
comp2
comp2
comp2
comp2
comp2
comp2
comp2
comp2
comp2

 

please suggest me a SAS code for doing it

 

thanks in advance

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Do like this 🙂

 

data have;
input companycode $;
datalines;
comp1
comp2
comp3
;

data want;
    set have;
    do _N_=1 to 10;
        output;
    end;
run;
Patrick
Opal | Level 21

@PeterClemmensen 

I assume that you've used the automatic variable _N_ is a typo. 

 

@srikanthyadav44 Don't use _N_ but "anything else" as name for the counter variable. 

data want(drop=_i);
    set have;
    do _i=1 to 10;
        output;
    end;
run;
PeterClemmensen
Tourmaline | Level 20

@Patrick, your assumption is incorrect. I like to use _N_ when a temporary counter variable is needed in a simple setting. If you have thoughts on the matter, I am all ears though 🙂 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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