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 🙂 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2496 views
  • 0 likes
  • 3 in conversation