Hello,
Below is the data.
Name | Exposure |
A | 45690 |
B | 3320 |
C | 12356 |
D | 73987 |
E | 5467 |
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?
@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 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;
Anytime 🙂
With regards to the same subject.
Now my data is
Name | Exposure | Count |
A | 45690 | 250 |
B | 3320 | 120 |
C | 12356 | 354 |
D | 73987 | 456 |
E | 5467 | 90 |
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?
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;
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?
Your answer was actually helpful, I modified the code a bit and got my desired output.
Thankyou.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.