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

Hello,

Below is the data.

 

NameExposure
A45690
B3320
C12356
D73987
E5467

 

I want is to create a new dataset, where it spilts the exposure value into that many number of rows. For eg, i want to create a table with Name and Exposure as coloums, and create 45690 rows having exposure value of 1 each and Name A for each row, then next i want to have 3320 rows with Exposure value 1 each and Name B for those corresponding values, similarly 12356 rows for Name C and etc.

Can anyone help me with this?

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

@Pumpp Hi and welcome to the SAS Community 🙂 

 

Sure thing:

 

data have;
input Name $ Exposure;
datalines;
A	45690
B	3320
C	12356
D	73987
E	5467
;

data want(drop=_);
   set have(rename=Exposure=_);
   Exposure=1;
   do _N_=1 to _;
      output;
   end;
run;

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

@Pumpp Hi and welcome to the SAS Community 🙂 

 

Sure thing:

 

data have;
input Name $ Exposure;
datalines;
A	45690
B	3320
C	12356
D	73987
E	5467
;

data want(drop=_);
   set have(rename=Exposure=_);
   Exposure=1;
   do _N_=1 to _;
      output;
   end;
run;
Pumpp
Obsidian | Level 7
Thank you very much. This was of great help.
 
Pumpp
Obsidian | Level 7

With regards to the same subject.

Now my data is 

NameExposureCount
A45690250
B3320120
C12356354
D73987456
E546790

I want to do the same thing, but 3rd coloum as Count included.

For example, Exposure has 45690 rows with values 1 each and Name A corresponding to that. What i want is a 3rd coloum as Count but only 250 rows having value 1 and remaining rows should have value is 0. Then do the same for Name B, but only 120 rows having count as 1 and remaining counts as 0.

What do I do for this?

PeterClemmensen
Tourmaline | Level 20

Small change

 

data have;
input Name $ Exposure Count;
datalines;
A 45690 250
B 3320  120
C 12356 354
D 73987 456
E 5467  90 
;

data want(drop=_);
   set have(rename=Exposure=_);
   Exposure=1;
   do _N_=1 to _;
      Exposure = _N_ <= Count;
      output;
   end;
run;
Pumpp
Obsidian | Level 7

This is not the what i wanted. In this the Exposure count stops after 250.

What I want is, for example taking 1st row from the Data Have, I want 45690 rows, where 1st Column has Name A, then 2nd column is Exposure having value 1(45690 times) and 3rd column as Count, where Count value is 1, but apprears only in the 1st 250 rows and for remaining rows (till row number 45690) has value 0.

I hope I made sense to my problem statement?

Pumpp
Obsidian | Level 7

Your answer was actually helpful, I modified the code a bit and got my desired output.

Thankyou.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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